Skip to content

Commit 642a7c5

Browse files
committed
rebuild for 1.5.0
1 parent 03e3808 commit 642a7c5

File tree

12 files changed

+223
-179
lines changed

12 files changed

+223
-179
lines changed

browser/react-widgets.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/css/react-widgets.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/common/ReplaceTransitionGroup.js

Lines changed: 88 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
"use strict";
1010

1111
var React = require('react')
12+
, startsWith = require('../util/filter').startsWith
1213
, cloneWithProps = require('../util/transferProps').cloneWithProps
1314
, transferPropsTo = require('../util/transferProps').mergeIntoProps
1415
, $ = require('../util/dom')
1516
, _ = require('../util/_');
1617

18+
19+
1720
module.exports = React.createClass({
1821

1922
displayName: 'ReplaceTransitionGroup',
@@ -31,95 +34,94 @@ module.exports = React.createClass({
3134
component: React.DOM.span,
3235
childFactory: function(a){ return a },
3336

34-
onAnimating: function(){},
35-
onAnimate: function(){}
37+
onAnimating: _.noop,
38+
onAnimate: _.noop
3639
};
3740
},
3841

3942
getInitialState: function() {
4043
return {
41-
children: React.Children.map(this.props.children, function(c){ return c })
44+
children: _.splat(this.props.children)
4245
};
4346
},
4447

4548
componentWillReceiveProps: function(nextProps) {
46-
var nextChildMapping = React.Children.map(nextProps.children, function(c){ return c })
47-
, prevChildMapping = this.state.children
48-
, key, hasOther, isNext;
49-
50-
//console.log(prevChildMapping, nextChildMapping)
51-
this.setState({
52-
children: _.merge(prevChildMapping, nextChildMapping)
53-
});
54-
55-
for(key in nextChildMapping) if( _.has(nextChildMapping, key) )
56-
{
57-
hasOther = prevChildMapping && _.has(prevChildMapping, key)
58-
isNext = !hasOther && !this.currentlyTransitioningKeys[key];
59-
60-
if ( isNext ) {
61-
this.next = key
62-
break
63-
}
49+
var nextChild = getChild(nextProps.children)
50+
, stack = this.state.children.slice()
51+
, next = stack[1]
52+
, last = stack[0];
53+
54+
var isLastChild = last && key(last) === key(nextChild)
55+
, isNextChild = next && key(next) === key(nextChild);
56+
57+
//no children
58+
if (!last) {
59+
stack.push(nextChild)
60+
this.entering = nextChild
6461
}
65-
66-
for(key in prevChildMapping) if( _.has(prevChildMapping, key) )
67-
{
68-
hasOther = nextChildMapping && _.has(nextChildMapping, key)
69-
isNext = !hasOther && !this.currentlyTransitioningKeys[key];
70-
71-
if ( isNext ) {
72-
this.current = key
73-
break
74-
}
62+
else if ( last && !next && !isLastChild) {
63+
//new child
64+
stack.push(nextChild)
65+
this.leaving = last
66+
this.entering = nextChild
7567
}
68+
else if ( last && next && !isLastChild && !isNextChild) {
69+
// the child is not the current one, exit the current one, add the new one
70+
// - shift the stack down
71+
stack.shift()
72+
stack.push(nextChild)
73+
this.leaving = next
74+
this.entering = nextChild
75+
}
76+
//new child that just needs to be re-rendered
77+
else if (isLastChild) stack.splice(0, 1, nextChild)
78+
else if (isNextChild) stack.splice(1, 1, nextChild)
79+
80+
if( this.state.children[0] !== stack[0] || this.state.children[1] !== stack[1] )
81+
this.setState({ children: stack });
7682
},
7783

7884
componentWillMount: function() {
79-
this.currentlyTransitioningKeys = {};
80-
this.current = null;
81-
this.next = null;
85+
this.animatingKeys = {};
86+
this.leaving = null;
87+
this.entering = null;
8288
},
8389

8490
componentDidUpdate: function() {
85-
var current = this.current
86-
, next = this.next
87-
, first = this.refs[current || next]
88-
, node = this.getDOMNode()
89-
, el = first && first.getDOMNode()
90-
, ht, wt;
91-
92-
if( el ) {
93-
ht = $.height(el) + 'px'
94-
wt = $.width(el) + 'px'
91+
var entering = this.entering
92+
, leaving = this.leaving
93+
, first = this.refs[key(entering) || key(leaving)]
94+
, node = this.getDOMNode()
95+
, el = first && first.getDOMNode();
9596

97+
if( el )
9698
$.css(node, {
9799
overflow: 'hidden',
98-
height: ht,
99-
width: wt
100+
height: $.height(el) + 'px',
101+
width: $.width(el) + 'px'
100102
})
101-
}
102-
103+
103104
this.props.onAnimating();
104105

105-
this.next = null;
106-
this.current = null;
106+
this.entering = null;
107+
this.leaving = null;
107108

108-
if ( next ) this.performEnter(next)
109-
if ( current) this.performLeave(current)
109+
if (entering) this.performEnter(key(entering))
110+
if (leaving) this.performLeave(key(leaving))
110111
},
111112

112113
performEnter: function(key) {
113-
this.currentlyTransitioningKeys[key] = true;
114-
115114
var component = this.refs[key];
116115

116+
if(!component) return
117+
118+
this.animatingKeys[key] = true;
119+
117120
if (component.componentWillEnter)
118121
component.componentWillEnter(
119122
this._handleDoneEntering.bind(this, key));
120123
else
121124
this._handleDoneEntering(key);
122-
123125
},
124126

125127
_tryFinish: function(){
@@ -128,84 +130,72 @@ module.exports = React.createClass({
128130
if ( this.isTransitioning() )
129131
return
130132

131-
$.css(node, {
132-
overflow: 'visible',
133-
height: '',
134-
width: ''
135-
})
133+
$.css(node, { overflow: 'visible', height: '', width: '' })
136134

137135
this.props.onAnimate()
138136
},
139137

140-
_handleDoneEntering: function(key) {
141-
var component = this.refs[key];
138+
_handleDoneEntering: function(enterkey) {
139+
var component = this.refs[enterkey];
142140

143-
if (component.componentDidEnter)
141+
if (component && component.componentDidEnter)
144142
component.componentDidEnter();
145143

146-
delete this.currentlyTransitioningKeys[key];
147-
148-
var currentChildMapping = React.Children.map(this.props.children, function(c){ return c })
144+
delete this.animatingKeys[enterkey];
149145

150-
if (!currentChildMapping || !_.has(currentChildMapping, key))
151-
this.performLeave(key); // This was removed before it had fully entered. Remove it.
146+
if ( key(this.props.children) !== enterkey)
147+
this.performLeave(enterkey); // This was removed before it had fully entered. Remove it.
152148

153149
this._tryFinish()
154150
},
155151

156152
isTransitioning: function(){
157-
return Object.keys(this.currentlyTransitioningKeys).length !== 0
153+
return Object.keys(this.animatingKeys).length !== 0
158154
},
159155

160156
performLeave: function(key) {
161157
var component = this.refs[key];
162158

163-
this.currentlyTransitioningKeys[key] = true;
159+
if(!component) return
160+
161+
this.animatingKeys[key] = true;
164162

165163
if (component.componentWillLeave)
166164
component.componentWillLeave(this._handleDoneLeaving.bind(this, key));
167165
else
168166
this._handleDoneLeaving(key);
169-
170167
},
171168

172-
_handleDoneLeaving: function(key) {
173-
var component = this.refs[key];
169+
_handleDoneLeaving: function(leavekey) {
170+
var component = this.refs[leavekey];
174171

175-
if (component.componentDidLeave)
172+
if (component && component.componentDidLeave)
176173
component.componentDidLeave();
177174

178-
delete this.currentlyTransitioningKeys[key];
179-
180-
var currentChildMapping = React.Children.map(this.props.children, function(c){ return c })
175+
delete this.animatingKeys[leavekey];
181176

182-
if (currentChildMapping && currentChildMapping.hasOwnProperty(key))
183-
this.performEnter(key); // This entered again before it fully left. Add it again.
177+
if (key(this.props.children) === leavekey )
178+
this.performEnter(leavekey); // This entered again before it fully left. Add it again.
184179
else {
185-
var newChildren = _.merge(this.state.children);
186-
delete newChildren[key];
187-
this.setState({children: newChildren});
180+
var newChildren = _.filter(this.state.children, function(c) {return key(c) !== leavekey;});
181+
this.setState({ children: newChildren });
188182
}
189183

190184
this._tryFinish()
191185
},
192186

193187
render: function() {
194-
var childrenToRender = {};
195-
196-
197-
for (var key in this.state.children) {
198-
199-
var child = this.state.children[key];
200-
201-
if (child) {
202-
childrenToRender[key] = cloneWithProps(
203-
this.props.childFactory(child),
204-
{ ref: key }
205-
);
206-
}
207-
}
208-
209-
return transferPropsTo(this.props, this.props.component(null, childrenToRender));
188+
var Component = this.props.component
189+
return transferPropsTo(this.props,
190+
Component(null, this.state.children.map(function(c) {return this.props.childFactory(c, key(c));}.bind(this)) ));
210191
}
211192
});
193+
194+
function getChild(children){
195+
return React.Children.only(children)
196+
}
197+
198+
//CHANGE 0.12.0
199+
function key(child){
200+
return child && (startsWith(React.version, '0.12') ? child.key : child.props.key)
201+
}

lib/common/slide-transition.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ var SlideChildGroup = React.createClass({displayName: 'SlideChildGroup',
1212
direction: React.PropTypes.oneOf(['left', 'right'])
1313
},
1414

15-
getDefaultProps: function(){
16-
return { duration: 250 }
17-
},
18-
1915
componentWillEnter: function(done) {
20-
var self = this
21-
, node = this.getDOMNode()
16+
var node = this.getDOMNode()
2217
, width = $.width(node)
2318
, direction = this.props.direction;
2419

@@ -28,21 +23,20 @@ var SlideChildGroup = React.createClass({displayName: 'SlideChildGroup',
2823

2924
$.css(node, { position: 'absolute', left: width + 'px' , top: 0 })
3025

31-
$.animate(node, { left: 0 }, self.props.duration, function(){
26+
$.animate(node, { left: 0 }, this.props.duration, function() {
3227

3328
$.css(node, {
34-
position: self.ORGINAL_POSITION,
29+
position: this.ORGINAL_POSITION,
3530
overflow: 'hidden'
3631
});
3732

38-
self.ORGINAL_POSITION = null
33+
this.ORGINAL_POSITION = null
3934
done && done()
40-
})
35+
}.bind(this))
4136
},
4237

4338
componentWillLeave: function(done) {
44-
var self = this
45-
, node = this.getDOMNode()
39+
var node = this.getDOMNode()
4640
, width = $.width(node)
4741
, direction = this.props.direction;
4842

@@ -52,15 +46,15 @@ var SlideChildGroup = React.createClass({displayName: 'SlideChildGroup',
5246

5347
$.css(node, { position: 'absolute', top: 0, left: 0})
5448

55-
$.animate(node, { left: width + 'px'}, self.props.duration, function(){
49+
$.animate(node, { left: width + 'px' }, this.props.duration, function() {
5650
$.css(node, {
57-
position: self.ORGINAL_POSITION,
51+
position: this.ORGINAL_POSITION,
5852
overflow: 'hidden'
5953
});
6054

61-
self.ORGINAL_POSITION = null
55+
this.ORGINAL_POSITION = null
6256
done && done()
63-
})
57+
}.bind(this))
6458
},
6559

6660
render: function() {
@@ -73,17 +67,19 @@ var SlideChildGroup = React.createClass({displayName: 'SlideChildGroup',
7367
module.exports = React.createClass({displayName: 'exports',
7468

7569
propTypes: {
76-
direction: React.PropTypes.oneOf(['left', 'right'])
70+
direction: React.PropTypes.oneOf(['left', 'right']),
71+
duration: React.PropTypes.number
7772
},
7873

7974
getDefaultProps: function(){
8075
return {
81-
direction: 'left'
76+
direction: 'left',
77+
duration: 250
8278
}
8379
},
8480

85-
_wrapChild: function(child) {
86-
return (SlideChildGroup({direction: this.props.direction}, child))
81+
_wrapChild: function(child, ref) {
82+
return (SlideChildGroup({ref: ref, direction: this.props.direction, duration: this.props.duration}, child))
8783
},
8884

8985
render: function() {

lib/less/core.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
}
138138

139139
ul.rw-list,
140-
ul.rw-checkboxlist {
140+
ul.rw-selectlist {
141141
.list-unstyled();
142142
padding: 5px 0;
143143
overflow: auto;

0 commit comments

Comments
 (0)