react 0.9.0 → 0.10.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/AutoFocusMixin.js +3 -1
- package/lib/DOMChildrenOperations.js +12 -6
- package/lib/DOMProperty.js +6 -4
- package/lib/DOMPropertyOperations.js +6 -6
- package/lib/DefaultDOMPropertyConfig.js +5 -12
- package/lib/EventPluginHub.js +2 -0
- package/lib/LinkedValueUtils.js +22 -23
- package/lib/React.js +3 -1
- package/lib/ReactBrowserComponentMixin.js +42 -0
- package/lib/ReactCSSTransitionGroup.js +10 -10
- package/lib/ReactComponent.js +76 -31
- package/lib/ReactComponentBrowserEnvironment.js +1 -35
- package/lib/ReactCompositeComponent.js +199 -67
- package/lib/ReactDOM.js +5 -5
- package/lib/ReactDOMButton.js +2 -1
- package/lib/ReactDOMComponent.js +22 -5
- package/lib/ReactDOMForm.js +3 -0
- package/lib/ReactDOMImg.js +3 -0
- package/lib/ReactDOMInput.js +2 -1
- package/lib/ReactDOMOption.js +11 -7
- package/lib/ReactDOMSelect.js +2 -1
- package/lib/ReactDOMTextarea.js +7 -3
- package/lib/ReactDefaultInjection.js +10 -0
- package/lib/ReactInjection.js +4 -0
- package/lib/ReactInputSelection.js +2 -1
- package/lib/ReactMount.js +13 -5
- package/lib/ReactMultiChild.js +10 -3
- package/lib/ReactOwner.js +6 -1
- package/lib/ReactPropTransferer.js +1 -1
- package/lib/ReactReconcileTransaction.js +7 -6
- package/lib/ReactServerRendering.js +38 -8
- package/lib/ReactServerRenderingTransaction.js +116 -0
- package/lib/ReactTextComponent.js +24 -2
- package/lib/ReactWithAddons.js +3 -1
- package/lib/cloneWithProps.js +7 -7
- package/lib/{ReactComponentEnvironment.js → emptyObject.js} +6 -5
- package/lib/focusNode.js +33 -0
- package/lib/instantiateReactComponent.js +70 -0
- package/lib/isNode.js +1 -1
- package/lib/monitorCodeUse.js +37 -0
- package/lib/shouldUpdateReactComponent.js +17 -14
- package/lib/traverseAllChildren.js +2 -1
- package/lib/update.js +159 -0
- package/package.json +1 -1
package/lib/isNode.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
function isNode(object) {
|
|
25
25
|
return !!(object && (
|
|
26
|
-
typeof Node
|
|
26
|
+
typeof Node === 'function' ? object instanceof Node :
|
|
27
27
|
typeof object === 'object' &&
|
|
28
28
|
typeof object.nodeType === 'number' &&
|
|
29
29
|
typeof object.nodeName === 'string'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2014 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule monitorCodeUse
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var invariant = require("./invariant");
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Provides open-source compatible instrumentation for monitoring certain API
|
|
25
|
+
* uses before we're ready to issue a warning or refactor. It accepts an event
|
|
26
|
+
* name which may only contain the characters [a-z0-9_] and an optional data
|
|
27
|
+
* object with further information.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
function monitorCodeUse(eventName, data) {
|
|
31
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
32
|
+
eventName && !/[^a-z0-9_]/.test(eventName),
|
|
33
|
+
'You must provide an eventName using only the characters [a-z0-9_]'
|
|
34
|
+
) : invariant(eventName && !/[^a-z0-9_]/.test(eventName)));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = monitorCodeUse;
|
|
@@ -20,33 +20,36 @@
|
|
|
20
20
|
"use strict";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Given a `
|
|
24
|
-
* should be updated as opposed to being destroyed or
|
|
23
|
+
* Given a `prevComponentInstance` and `nextComponent`, determines if
|
|
24
|
+
* `prevComponentInstance` should be updated as opposed to being destroyed or
|
|
25
|
+
* replaced by a new instance. The second argument is a descriptor. Future
|
|
26
|
+
* versions of the reconciler should only compare descriptors to other
|
|
27
|
+
* descriptors.
|
|
25
28
|
*
|
|
26
|
-
* @param {?object}
|
|
27
|
-
* @param {?object}
|
|
28
|
-
* @return {boolean} True if `
|
|
29
|
+
* @param {?object} prevComponentInstance
|
|
30
|
+
* @param {?object} nextDescriptor
|
|
31
|
+
* @return {boolean} True if `prevComponentInstance` should be updated.
|
|
29
32
|
* @protected
|
|
30
33
|
*/
|
|
31
|
-
function shouldUpdateReactComponent(
|
|
34
|
+
function shouldUpdateReactComponent(prevComponentInstance, nextDescriptor) {
|
|
32
35
|
// TODO: Remove warning after a release.
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
(
|
|
36
|
-
(
|
|
36
|
+
if (prevComponentInstance && nextDescriptor &&
|
|
37
|
+
prevComponentInstance.constructor === nextDescriptor.constructor && (
|
|
38
|
+
(prevComponentInstance.props && prevComponentInstance.props.key) ===
|
|
39
|
+
(nextDescriptor.props && nextDescriptor.props.key)
|
|
37
40
|
)) {
|
|
38
|
-
if (
|
|
41
|
+
if (prevComponentInstance._owner === nextDescriptor._owner) {
|
|
39
42
|
return true;
|
|
40
43
|
} else {
|
|
41
44
|
if ("production" !== process.env.NODE_ENV) {
|
|
42
|
-
if (
|
|
45
|
+
if (prevComponentInstance.state) {
|
|
43
46
|
console.warn(
|
|
44
47
|
'A recent change to React has been found to impact your code. ' +
|
|
45
48
|
'A mounted component will now be unmounted and replaced by a ' +
|
|
46
49
|
'component (of the same class) if their owners are different. ' +
|
|
47
50
|
'Previously, ownership was not considered when updating.',
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
prevComponentInstance,
|
|
52
|
+
nextDescriptor
|
|
50
53
|
);
|
|
51
54
|
}
|
|
52
55
|
}
|
|
@@ -126,7 +126,8 @@ var traverseAllChildrenImpl =
|
|
|
126
126
|
// All of the above are perceived as null.
|
|
127
127
|
callback(traverseContext, null, storageName, indexSoFar);
|
|
128
128
|
subtreeCount = 1;
|
|
129
|
-
} else if (children.
|
|
129
|
+
} else if (children.type && children.type.prototype &&
|
|
130
|
+
children.type.prototype.mountComponentIntoNode) {
|
|
130
131
|
callback(traverseContext, children, storageName, indexSoFar);
|
|
131
132
|
subtreeCount = 1;
|
|
132
133
|
} else {
|
package/lib/update.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-2014 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule update
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var copyProperties = require("./copyProperties");
|
|
22
|
+
var keyOf = require("./keyOf");
|
|
23
|
+
var invariant = require("./invariant");
|
|
24
|
+
|
|
25
|
+
function shallowCopy(x) {
|
|
26
|
+
if (Array.isArray(x)) {
|
|
27
|
+
return x.concat();
|
|
28
|
+
} else if (x && typeof x === 'object') {
|
|
29
|
+
return copyProperties(new x.constructor(), x);
|
|
30
|
+
} else {
|
|
31
|
+
return x;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var DIRECTIVE_PUSH = keyOf({$push: null});
|
|
36
|
+
var DIRECTIVE_UNSHIFT = keyOf({$unshift: null});
|
|
37
|
+
var DIRECTIVE_SPLICE = keyOf({$splice: null});
|
|
38
|
+
var DIRECTIVE_SET = keyOf({$set: null});
|
|
39
|
+
var DIRECTIVE_MERGE = keyOf({$merge: null});
|
|
40
|
+
|
|
41
|
+
var ALL_DIRECTIVES_LIST = [
|
|
42
|
+
DIRECTIVE_PUSH,
|
|
43
|
+
DIRECTIVE_UNSHIFT,
|
|
44
|
+
DIRECTIVE_SPLICE,
|
|
45
|
+
DIRECTIVE_SET,
|
|
46
|
+
DIRECTIVE_MERGE
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
var ALL_DIRECTIVES_SET = {};
|
|
50
|
+
|
|
51
|
+
ALL_DIRECTIVES_LIST.forEach(function(directive) {
|
|
52
|
+
ALL_DIRECTIVES_SET[directive] = true;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function invariantArrayCase(value, spec, directive) {
|
|
56
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
57
|
+
Array.isArray(value),
|
|
58
|
+
'update(): expected target of %s to be an array; got %s.',
|
|
59
|
+
directive,
|
|
60
|
+
value
|
|
61
|
+
) : invariant(Array.isArray(value)));
|
|
62
|
+
var specValue = spec[directive];
|
|
63
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
64
|
+
Array.isArray(specValue),
|
|
65
|
+
'update(): expected spec of %s to be an array; got %s. ' +
|
|
66
|
+
'Did you forget to wrap your parameter in an array?',
|
|
67
|
+
directive,
|
|
68
|
+
specValue
|
|
69
|
+
) : invariant(Array.isArray(specValue)));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function update(value, spec) {
|
|
73
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
74
|
+
typeof spec === 'object',
|
|
75
|
+
'update(): You provided a key path to update() that did not contain one ' +
|
|
76
|
+
'of %s. Did you forget to include {%s: ...}?',
|
|
77
|
+
ALL_DIRECTIVES_LIST.join(', '),
|
|
78
|
+
DIRECTIVE_SET
|
|
79
|
+
) : invariant(typeof spec === 'object'));
|
|
80
|
+
|
|
81
|
+
if (spec.hasOwnProperty(DIRECTIVE_SET)) {
|
|
82
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
83
|
+
Object.keys(spec).length === 1,
|
|
84
|
+
'Cannot have more than one key in an object with %s',
|
|
85
|
+
DIRECTIVE_SET
|
|
86
|
+
) : invariant(Object.keys(spec).length === 1));
|
|
87
|
+
|
|
88
|
+
return spec[DIRECTIVE_SET];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
var nextValue = shallowCopy(value);
|
|
92
|
+
|
|
93
|
+
if (spec.hasOwnProperty(DIRECTIVE_MERGE)) {
|
|
94
|
+
var mergeObj = spec[DIRECTIVE_MERGE];
|
|
95
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
96
|
+
mergeObj && typeof mergeObj === 'object',
|
|
97
|
+
'update(): %s expects a spec of type \'object\'; got %s',
|
|
98
|
+
DIRECTIVE_MERGE,
|
|
99
|
+
mergeObj
|
|
100
|
+
) : invariant(mergeObj && typeof mergeObj === 'object'));
|
|
101
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
102
|
+
nextValue && typeof nextValue === 'object',
|
|
103
|
+
'update(): %s expects a target of type \'object\'; got %s',
|
|
104
|
+
DIRECTIVE_MERGE,
|
|
105
|
+
nextValue
|
|
106
|
+
) : invariant(nextValue && typeof nextValue === 'object'));
|
|
107
|
+
copyProperties(nextValue, spec[DIRECTIVE_MERGE]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (spec.hasOwnProperty(DIRECTIVE_PUSH)) {
|
|
111
|
+
invariantArrayCase(value, spec, DIRECTIVE_PUSH);
|
|
112
|
+
spec[DIRECTIVE_PUSH].forEach(function(item) {
|
|
113
|
+
nextValue.push(item);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (spec.hasOwnProperty(DIRECTIVE_UNSHIFT)) {
|
|
118
|
+
invariantArrayCase(value, spec, DIRECTIVE_UNSHIFT);
|
|
119
|
+
spec[DIRECTIVE_UNSHIFT].forEach(function(item) {
|
|
120
|
+
nextValue.unshift(item);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (spec.hasOwnProperty(DIRECTIVE_SPLICE)) {
|
|
125
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
126
|
+
Array.isArray(value),
|
|
127
|
+
'Expected %s target to be an array; got %s',
|
|
128
|
+
DIRECTIVE_SPLICE,
|
|
129
|
+
value
|
|
130
|
+
) : invariant(Array.isArray(value)));
|
|
131
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
132
|
+
Array.isArray(spec[DIRECTIVE_SPLICE]),
|
|
133
|
+
'update(): expected spec of %s to be an array of arrays; got %s. ' +
|
|
134
|
+
'Did you forget to wrap your parameters in an array?',
|
|
135
|
+
DIRECTIVE_SPLICE,
|
|
136
|
+
spec[DIRECTIVE_SPLICE]
|
|
137
|
+
) : invariant(Array.isArray(spec[DIRECTIVE_SPLICE])));
|
|
138
|
+
spec[DIRECTIVE_SPLICE].forEach(function(args) {
|
|
139
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
140
|
+
Array.isArray(args),
|
|
141
|
+
'update(): expected spec of %s to be an array of arrays; got %s. ' +
|
|
142
|
+
'Did you forget to wrap your parameters in an array?',
|
|
143
|
+
DIRECTIVE_SPLICE,
|
|
144
|
+
spec[DIRECTIVE_SPLICE]
|
|
145
|
+
) : invariant(Array.isArray(args)));
|
|
146
|
+
nextValue.splice.apply(nextValue, args);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
for (var k in spec) {
|
|
151
|
+
if (!ALL_DIRECTIVES_SET[k]) {
|
|
152
|
+
nextValue[k] = update(value[k], spec[k]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return nextValue;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
module.exports = update;
|