Skip to content

Commit 08e4420

Browse files
committed
Use setState transaction for TransitionGroup instead of extra property
1 parent 205273d commit 08e4420

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

src/addons/transitions/ReactTransitionGroup.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ var ReactTransitionGroup = React.createClass({
8989
},
9090

9191
componentDidUpdate: function() {
92-
this.updatedChildren = null;
93-
9492
var keysToEnter = this.keysToEnter;
9593
this.keysToEnter = [];
9694
keysToEnter.forEach(this.performEnter);
@@ -195,13 +193,11 @@ var ReactTransitionGroup = React.createClass({
195193
// This entered again before it fully left. Add it again.
196194
this.performEnter(key);
197195
} else {
198-
// As this.state.children will not be updated until next render, we keep
199-
// this.updatedChildren state to avoid losing all but the last removal.
200-
// It's cleaned after this.state is updated, in componentDidUpdate.
201-
if (!this.updatedChildren)
202-
this.updatedChildren = assign({}, this.state.children);
203-
delete this.updatedChildren[key];
204-
this.setState({children: this.updatedChildren});
196+
this.setState(function(state) {
197+
var newChildren = assign({}, state.children);
198+
delete newChildren[key];
199+
return {children: newChildren};
200+
});
205201
}
206202
},
207203

src/addons/transitions/__tests__/ReactTransitionGroup-test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,24 +215,24 @@ describe('ReactTransitionGroup', function() {
215215

216216
var Child = React.createClass({
217217
componentDidMount: function() {
218-
log.push('didMount'+this.props.id);
218+
log.push('didMount' + this.props.id);
219219
},
220220
componentWillEnter: function(cb) {
221-
log.push('willEnter'+this.props.id);
221+
log.push('willEnter' + this.props.id);
222222
cb();
223223
},
224224
componentDidEnter: function() {
225-
log.push('didEnter'+this.props.id);
225+
log.push('didEnter' + this.props.id);
226226
},
227227
componentWillLeave: function(cb) {
228-
log.push('willLeave'+this.props.id);
228+
log.push('willLeave' + this.props.id);
229229
cb();
230230
},
231231
componentDidLeave: function() {
232-
log.push('didLeave'+this.props.id);
232+
log.push('didLeave' + this.props.id);
233233
},
234234
componentWillUnmount: function() {
235-
log.push('willUnmount'+this.props.id);
235+
log.push('willUnmount' + this.props.id);
236236
},
237237
render: function() {
238238
return <span />;
@@ -258,14 +258,14 @@ describe('ReactTransitionGroup', function() {
258258

259259
instance.setState({count: 3});
260260
expect(log).toEqual([
261-
'didMount1', 'didMount2', 'willEnter1', 'didEnter1',
261+
'didMount1', 'didMount2', 'willEnter1', 'didEnter1',
262262
'willEnter2', 'didEnter2'
263263
]);
264264
log = [];
265265

266266
instance.setState({count: 0});
267267
expect(log).toEqual([
268-
'willLeave0', 'didLeave0', 'willLeave1', 'didLeave1',
268+
'willLeave0', 'didLeave0', 'willLeave1', 'didLeave1',
269269
'willLeave2', 'didLeave2', 'willUnmount0', 'willUnmount1', 'willUnmount2'
270270
]);
271271
});

0 commit comments

Comments
 (0)