Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactTransitions: Don't animate undefined children #537

Merged
merged 2 commits into from
Dec 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/addons/transitions/ReactTransitionGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var ReactTransitionGroupMixin = {

var children = {};
var childMapping = ReactTransitionKeySet.getChildMapping(sourceChildren);

var transitionConfig = this.getTransitionConfig();
var currentKeys = ReactTransitionKeySet.mergeKeySets(
this._transitionGroupCurrentKeys,
Expand Down
3 changes: 3 additions & 0 deletions src/addons/transitions/ReactTransitionKeySet.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ var ReactTransitionKeySet = {
* in `next` in a reasonable order.
*/
mergeKeySets: function(prev, next) {
prev = prev || {};
next = next || {};

var keySet = {};
var prevKeys = Object.keys(prev).concat([MERGE_KEY_SETS_TAIL_SENTINEL]);
var nextKeys = Object.keys(next).concat([MERGE_KEY_SETS_TAIL_SENTINEL]);
Expand Down
21 changes: 15 additions & 6 deletions src/addons/transitions/__tests__/ReactTransitionGroup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ var mocks;
// Most of the real functionality is covered in other unit tests, this just
// makes sure we're wired up correctly.
describe('ReactTransitionGroup', function() {
var container;

beforeEach(function() {
React = require('React');
ReactTransitionGroup = require('ReactTransitionGroup');
mocks = require('mocks');

container = document.createElement('div');
});

it('should warn after time with no transitionend', function() {
var container;
var a;

container = document.createElement('div');
a = React.renderComponent(
var a = React.renderComponent(
<ReactTransitionGroup transitionName="yolo">
<span key="one" id="one" />
</ReactTransitionGroup>,
Expand Down Expand Up @@ -65,7 +65,6 @@ describe('ReactTransitionGroup', function() {
});

it('should keep both sets of DOM nodes around', function() {
var container = document.createElement('div');
var a = React.renderComponent(
<ReactTransitionGroup transitionName="yolo">
<span key="one" id="one" />
Expand All @@ -83,4 +82,14 @@ describe('ReactTransitionGroup', function() {
expect(a.getDOMNode().childNodes[0].id).toBe('two');
expect(a.getDOMNode().childNodes[1].id).toBe('one');
});

describe('with an undefined child', function () {
it('should fail silently', function () {
var a = React.renderComponent(
<ReactTransitionGroup transitionName="yolo">
</ReactTransitionGroup>,
container
);
});
});
});
26 changes: 26 additions & 0 deletions src/addons/transitions/__tests__/ReactTransitionKeySet-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,30 @@ describe('ReactTransitionKeySet', function() {
five: true
});
});

it('should support mergeKeySets with undefined input', function () {
var prev = {
one: true,
two: true
};

var next = undefined;

expect(ReactTransitionKeySet.mergeKeySets(prev, next)).toEqual({
one: true,
two: true
});

prev = undefined;

next = {
three: true,
four: true
};

expect(ReactTransitionKeySet.mergeKeySets(prev, next)).toEqual({
three: true,
four: true
});
});
});