react 0.8.0 → 0.9.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/README.md +0 -8
- package/addons.js +0 -3
- package/lib/AutoFocusMixin.js +30 -0
- package/lib/CSSCore.js +22 -21
- package/lib/CSSProperty.js +31 -0
- package/lib/ChangeEventPlugin.js +26 -4
- package/lib/ClientReactRootIndex.js +30 -0
- package/lib/CompositionEventPlugin.js +57 -9
- package/lib/DOMChildrenOperations.js +32 -2
- package/lib/DOMProperty.js +2 -0
- package/lib/DOMPropertyOperations.js +14 -1
- package/lib/Danger.js +8 -7
- package/lib/DefaultDOMPropertyConfig.js +12 -2
- package/lib/EnterLeaveEventPlugin.js +37 -4
- package/lib/EventConstants.js +3 -0
- package/lib/EventListener.js +42 -34
- package/lib/EventPluginHub.js +113 -12
- package/lib/EventPluginRegistry.js +39 -16
- package/lib/EventPluginUtils.js +32 -3
- package/lib/EventPropagators.js +6 -42
- package/lib/ExecutionEnvironment.js +3 -0
- package/lib/LinkedValueUtils.js +161 -0
- package/lib/PooledClass.js +6 -0
- package/lib/React.js +27 -3
- package/lib/ReactCSSTransitionGroup.js +65 -0
- package/lib/{ReactTransitionableChild.js → ReactCSSTransitionGroupChild.js} +21 -35
- package/lib/ReactComponent.js +87 -52
- package/lib/ReactComponentBrowserEnvironment.js +67 -49
- package/lib/ReactComponentEnvironment.js +2 -0
- package/lib/ReactCompositeComponent.js +547 -112
- package/lib/ReactContext.js +67 -0
- package/lib/ReactDOM.js +13 -0
- package/lib/ReactDOMButton.js +4 -0
- package/lib/ReactDOMComponent.js +46 -21
- package/lib/ReactDOMForm.js +9 -2
- package/lib/ReactDOMIDOperations.js +105 -60
- package/lib/ReactDOMImg.js +58 -0
- package/lib/ReactDOMInput.js +26 -14
- package/lib/ReactDOMOption.js +1 -0
- package/lib/ReactDOMSelect.js +36 -17
- package/lib/ReactDOMTextarea.js +12 -8
- package/lib/ReactDefaultInjection.js +50 -26
- package/lib/ReactDefaultPerf.js +207 -370
- package/lib/ReactDefaultPerfAnalysis.js +199 -0
- package/lib/ReactErrorUtils.js +5 -14
- package/lib/ReactEventEmitter.js +141 -145
- package/lib/ReactEventEmitterMixin.js +0 -32
- package/lib/ReactEventTopLevelCallback.js +32 -12
- package/lib/ReactInjection.js +39 -0
- package/lib/ReactInstanceHandles.js +35 -19
- package/lib/ReactLink.js +1 -1
- package/lib/ReactMount.js +127 -103
- package/lib/ReactMountReady.js +1 -1
- package/lib/ReactMultiChild.js +30 -46
- package/lib/ReactMultiChildUpdateTypes.js +2 -0
- package/lib/ReactOwner.js +10 -2
- package/lib/ReactPerf.js +5 -8
- package/lib/ReactPropTransferer.js +40 -21
- package/lib/ReactPropTypeLocationNames.js +31 -0
- package/lib/ReactPropTypeLocations.js +29 -0
- package/lib/ReactPropTypes.js +248 -47
- package/lib/ReactPutListenerQueue.js +61 -0
- package/lib/ReactReconcileTransaction.js +20 -0
- package/lib/ReactRootIndex.js +36 -0
- package/lib/ReactServerRendering.js +8 -11
- package/lib/ReactTextComponent.js +8 -3
- package/lib/{ReactTransitionKeySet.js → ReactTransitionChildMapping.js} +42 -47
- package/lib/ReactTransitionGroup.js +132 -57
- package/lib/ReactUpdates.js +14 -11
- package/lib/ReactWithAddons.js +7 -2
- package/lib/SelectEventPlugin.js +22 -39
- package/lib/ServerReactRootIndex.js +36 -0
- package/lib/SimpleEventPlugin.js +54 -6
- package/lib/SyntheticClipboardEvent.js +7 -1
- package/lib/SyntheticDragEvent.js +44 -0
- package/lib/SyntheticEvent.js +2 -1
- package/lib/SyntheticKeyboardEvent.js +4 -2
- package/lib/SyntheticWheelEvent.js +10 -7
- package/lib/Transaction.js +61 -36
- package/lib/cloneWithProps.js +59 -0
- package/lib/createArrayFrom.js +10 -13
- package/lib/createFullPageComponent.js +63 -0
- package/lib/cx.js +2 -2
- package/lib/flattenChildren.js +5 -2
- package/lib/getActiveElement.js +4 -3
- package/lib/getEventKey.js +85 -0
- package/lib/getMarkupWrap.js +10 -0
- package/lib/getTextContentAccessor.js +5 -3
- package/lib/getUnboundedScrollPosition.js +2 -2
- package/lib/invariant.js +12 -4
- package/lib/isEventSupported.js +7 -11
- package/lib/mergeHelpers.js +5 -6
- package/lib/onlyChild.js +43 -0
- package/lib/shouldUpdateReactComponent.js +58 -0
- package/lib/toArray.js +75 -0
- package/lib/traverseAllChildren.js +69 -7
- package/lib/warning.js +40 -0
- package/package.json +2 -3
- package/react.js +0 -3
- package/ReactJSErrors.js +0 -40
- package/lib/$.js +0 -46
- package/lib/CallbackRegistry.js +0 -91
- package/lib/LinkedValueMixin.js +0 -68
- package/lib/ex.js +0 -49
- package/lib/filterAttributes.js +0 -45
- package/lib/ge.js +0 -76
- package/lib/mutateHTMLNodeWithMarkup.js +0 -100
|
@@ -63,11 +63,19 @@ function recomputePluginOrdering() {
|
|
|
63
63
|
var publishedEvents = PluginModule.eventTypes;
|
|
64
64
|
for (var eventName in publishedEvents) {
|
|
65
65
|
("production" !== process.env.NODE_ENV ? invariant(
|
|
66
|
-
publishEventForPlugin(
|
|
66
|
+
publishEventForPlugin(
|
|
67
|
+
publishedEvents[eventName],
|
|
68
|
+
PluginModule,
|
|
69
|
+
eventName
|
|
70
|
+
),
|
|
67
71
|
'EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.',
|
|
68
72
|
eventName,
|
|
69
73
|
pluginName
|
|
70
|
-
) : invariant(publishEventForPlugin(
|
|
74
|
+
) : invariant(publishEventForPlugin(
|
|
75
|
+
publishedEvents[eventName],
|
|
76
|
+
PluginModule,
|
|
77
|
+
eventName
|
|
78
|
+
)));
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
81
|
}
|
|
@@ -80,18 +88,26 @@ function recomputePluginOrdering() {
|
|
|
80
88
|
* @return {boolean} True if the event was successfully published.
|
|
81
89
|
* @private
|
|
82
90
|
*/
|
|
83
|
-
function publishEventForPlugin(dispatchConfig, PluginModule) {
|
|
91
|
+
function publishEventForPlugin(dispatchConfig, PluginModule, eventName) {
|
|
84
92
|
var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
|
|
85
93
|
if (phasedRegistrationNames) {
|
|
86
94
|
for (var phaseName in phasedRegistrationNames) {
|
|
87
95
|
if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
|
|
88
96
|
var phasedRegistrationName = phasedRegistrationNames[phaseName];
|
|
89
|
-
publishRegistrationName(
|
|
97
|
+
publishRegistrationName(
|
|
98
|
+
phasedRegistrationName,
|
|
99
|
+
PluginModule,
|
|
100
|
+
eventName
|
|
101
|
+
);
|
|
90
102
|
}
|
|
91
103
|
}
|
|
92
104
|
return true;
|
|
93
105
|
} else if (dispatchConfig.registrationName) {
|
|
94
|
-
publishRegistrationName(
|
|
106
|
+
publishRegistrationName(
|
|
107
|
+
dispatchConfig.registrationName,
|
|
108
|
+
PluginModule,
|
|
109
|
+
eventName
|
|
110
|
+
);
|
|
95
111
|
return true;
|
|
96
112
|
}
|
|
97
113
|
return false;
|
|
@@ -105,14 +121,16 @@ function publishEventForPlugin(dispatchConfig, PluginModule) {
|
|
|
105
121
|
* @param {object} PluginModule Plugin publishing the event.
|
|
106
122
|
* @private
|
|
107
123
|
*/
|
|
108
|
-
function publishRegistrationName(registrationName, PluginModule) {
|
|
124
|
+
function publishRegistrationName(registrationName, PluginModule, eventName) {
|
|
109
125
|
("production" !== process.env.NODE_ENV ? invariant(
|
|
110
|
-
!EventPluginRegistry.
|
|
126
|
+
!EventPluginRegistry.registrationNameModules[registrationName],
|
|
111
127
|
'EventPluginHub: More than one plugin attempted to publish the same ' +
|
|
112
128
|
'registration name, `%s`.',
|
|
113
129
|
registrationName
|
|
114
|
-
) : invariant(!EventPluginRegistry.
|
|
115
|
-
EventPluginRegistry.
|
|
130
|
+
) : invariant(!EventPluginRegistry.registrationNameModules[registrationName]));
|
|
131
|
+
EventPluginRegistry.registrationNameModules[registrationName] = PluginModule;
|
|
132
|
+
EventPluginRegistry.registrationNameDependencies[registrationName] =
|
|
133
|
+
PluginModule.eventTypes[eventName].dependencies;
|
|
116
134
|
}
|
|
117
135
|
|
|
118
136
|
/**
|
|
@@ -130,7 +148,12 @@ var EventPluginRegistry = {
|
|
|
130
148
|
/**
|
|
131
149
|
* Mapping from registration names to plugin modules.
|
|
132
150
|
*/
|
|
133
|
-
|
|
151
|
+
registrationNameModules: {},
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Mapping from registration name to event name
|
|
155
|
+
*/
|
|
156
|
+
registrationNameDependencies: {},
|
|
134
157
|
|
|
135
158
|
/**
|
|
136
159
|
* Injects an ordering of plugins (by plugin name). This allows the ordering
|
|
@@ -194,7 +217,7 @@ var EventPluginRegistry = {
|
|
|
194
217
|
getPluginModuleForEvent: function(event) {
|
|
195
218
|
var dispatchConfig = event.dispatchConfig;
|
|
196
219
|
if (dispatchConfig.registrationName) {
|
|
197
|
-
return EventPluginRegistry.
|
|
220
|
+
return EventPluginRegistry.registrationNameModules[
|
|
198
221
|
dispatchConfig.registrationName
|
|
199
222
|
] || null;
|
|
200
223
|
}
|
|
@@ -202,7 +225,7 @@ var EventPluginRegistry = {
|
|
|
202
225
|
if (!dispatchConfig.phasedRegistrationNames.hasOwnProperty(phase)) {
|
|
203
226
|
continue;
|
|
204
227
|
}
|
|
205
|
-
var PluginModule = EventPluginRegistry.
|
|
228
|
+
var PluginModule = EventPluginRegistry.registrationNameModules[
|
|
206
229
|
dispatchConfig.phasedRegistrationNames[phase]
|
|
207
230
|
];
|
|
208
231
|
if (PluginModule) {
|
|
@@ -224,10 +247,10 @@ var EventPluginRegistry = {
|
|
|
224
247
|
}
|
|
225
248
|
}
|
|
226
249
|
EventPluginRegistry.plugins.length = 0;
|
|
227
|
-
var
|
|
228
|
-
for (var registrationName in
|
|
229
|
-
if (
|
|
230
|
-
delete
|
|
250
|
+
var registrationNameModules = EventPluginRegistry.registrationNameModules;
|
|
251
|
+
for (var registrationName in registrationNameModules) {
|
|
252
|
+
if (registrationNameModules.hasOwnProperty(registrationName)) {
|
|
253
|
+
delete registrationNameModules[registrationName];
|
|
231
254
|
}
|
|
232
255
|
}
|
|
233
256
|
}
|
package/lib/EventPluginUtils.js
CHANGED
|
@@ -22,6 +22,28 @@ var EventConstants = require("./EventConstants");
|
|
|
22
22
|
|
|
23
23
|
var invariant = require("./invariant");
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Injected dependencies:
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* - `Mount`: [required] Module that can convert between React dom IDs and
|
|
31
|
+
* actual node references.
|
|
32
|
+
*/
|
|
33
|
+
var injection = {
|
|
34
|
+
Mount: null,
|
|
35
|
+
injectMount: function(InjectedMount) {
|
|
36
|
+
injection.Mount = InjectedMount;
|
|
37
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
38
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
39
|
+
InjectedMount && InjectedMount.getNode,
|
|
40
|
+
'EventPluginUtils.injection.injectMount(...): Injected Mount module ' +
|
|
41
|
+
'is missing getNode.'
|
|
42
|
+
) : invariant(InjectedMount && InjectedMount.getNode));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
25
47
|
var topLevelTypes = EventConstants.topLevelTypes;
|
|
26
48
|
|
|
27
49
|
function isEndish(topLevelType) {
|
|
@@ -39,6 +61,7 @@ function isStartish(topLevelType) {
|
|
|
39
61
|
topLevelType === topLevelTypes.topTouchStart;
|
|
40
62
|
}
|
|
41
63
|
|
|
64
|
+
|
|
42
65
|
var validateEventDispatches;
|
|
43
66
|
if ("production" !== process.env.NODE_ENV) {
|
|
44
67
|
validateEventDispatches = function(event) {
|
|
@@ -90,7 +113,10 @@ function forEachEventDispatch(event, cb) {
|
|
|
90
113
|
* @param {string} domID DOM id to pass to the callback.
|
|
91
114
|
*/
|
|
92
115
|
function executeDispatch(event, listener, domID) {
|
|
93
|
-
|
|
116
|
+
event.currentTarget = injection.Mount.getNode(domID);
|
|
117
|
+
var returnValue = listener(event, domID);
|
|
118
|
+
event.currentTarget = null;
|
|
119
|
+
return returnValue;
|
|
94
120
|
}
|
|
95
121
|
|
|
96
122
|
/**
|
|
@@ -175,11 +201,14 @@ var EventPluginUtils = {
|
|
|
175
201
|
isEndish: isEndish,
|
|
176
202
|
isMoveish: isMoveish,
|
|
177
203
|
isStartish: isStartish,
|
|
204
|
+
|
|
205
|
+
executeDirectDispatch: executeDirectDispatch,
|
|
206
|
+
executeDispatch: executeDispatch,
|
|
178
207
|
executeDispatchesInOrder: executeDispatchesInOrder,
|
|
179
208
|
executeDispatchesInOrderStopAtTrue: executeDispatchesInOrderStopAtTrue,
|
|
180
|
-
executeDirectDispatch: executeDirectDispatch,
|
|
181
209
|
hasDispatches: hasDispatches,
|
|
182
|
-
|
|
210
|
+
injection: injection,
|
|
211
|
+
useTouchEvents: false
|
|
183
212
|
};
|
|
184
213
|
|
|
185
214
|
module.exports = EventPluginUtils;
|
package/lib/EventPropagators.js
CHANGED
|
@@ -18,39 +18,14 @@
|
|
|
18
18
|
|
|
19
19
|
"use strict";
|
|
20
20
|
|
|
21
|
-
var CallbackRegistry = require("./CallbackRegistry");
|
|
22
21
|
var EventConstants = require("./EventConstants");
|
|
22
|
+
var EventPluginHub = require("./EventPluginHub");
|
|
23
23
|
|
|
24
24
|
var accumulate = require("./accumulate");
|
|
25
25
|
var forEachAccumulated = require("./forEachAccumulated");
|
|
26
|
-
var getListener = CallbackRegistry.getListener;
|
|
27
|
-
var PropagationPhases = EventConstants.PropagationPhases;
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* - `InstanceHandle`: [required] Module that performs logical traversals of DOM
|
|
35
|
-
* hierarchy given ids of the logical DOM elements involved.
|
|
36
|
-
*/
|
|
37
|
-
var injection = {
|
|
38
|
-
InstanceHandle: null,
|
|
39
|
-
injectInstanceHandle: function(InjectedInstanceHandle) {
|
|
40
|
-
injection.InstanceHandle = InjectedInstanceHandle;
|
|
41
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
42
|
-
injection.validate();
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
validate: function() {
|
|
46
|
-
var invalid = !injection.InstanceHandle||
|
|
47
|
-
!injection.InstanceHandle.traverseTwoPhase ||
|
|
48
|
-
!injection.InstanceHandle.traverseEnterLeave;
|
|
49
|
-
if (invalid) {
|
|
50
|
-
throw new Error('InstanceHandle not injected before use!');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
27
|
+
var PropagationPhases = EventConstants.PropagationPhases;
|
|
28
|
+
var getListener = EventPluginHub.getListener;
|
|
54
29
|
|
|
55
30
|
/**
|
|
56
31
|
* Some event types have a notion of different registration names for different
|
|
@@ -73,7 +48,6 @@ function accumulateDirectionalDispatches(domID, upwards, event) {
|
|
|
73
48
|
if (!domID) {
|
|
74
49
|
throw new Error('Dispatching id must not be null');
|
|
75
50
|
}
|
|
76
|
-
injection.validate();
|
|
77
51
|
}
|
|
78
52
|
var phase = upwards ? PropagationPhases.bubbled : PropagationPhases.captured;
|
|
79
53
|
var listener = listenerAtPhase(domID, event, phase);
|
|
@@ -92,7 +66,7 @@ function accumulateDirectionalDispatches(domID, upwards, event) {
|
|
|
92
66
|
*/
|
|
93
67
|
function accumulateTwoPhaseDispatchesSingle(event) {
|
|
94
68
|
if (event && event.dispatchConfig.phasedRegistrationNames) {
|
|
95
|
-
injection.
|
|
69
|
+
EventPluginHub.injection.getInstanceHandle().traverseTwoPhase(
|
|
96
70
|
event.dispatchMarker,
|
|
97
71
|
accumulateDirectionalDispatches,
|
|
98
72
|
event
|
|
@@ -129,17 +103,11 @@ function accumulateDirectDispatchesSingle(event) {
|
|
|
129
103
|
}
|
|
130
104
|
|
|
131
105
|
function accumulateTwoPhaseDispatches(events) {
|
|
132
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
133
|
-
injection.validate();
|
|
134
|
-
}
|
|
135
106
|
forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
|
|
136
107
|
}
|
|
137
108
|
|
|
138
109
|
function accumulateEnterLeaveDispatches(leave, enter, fromID, toID) {
|
|
139
|
-
|
|
140
|
-
injection.validate();
|
|
141
|
-
}
|
|
142
|
-
injection.InstanceHandle.traverseEnterLeave(
|
|
110
|
+
EventPluginHub.injection.getInstanceHandle().traverseEnterLeave(
|
|
143
111
|
fromID,
|
|
144
112
|
toID,
|
|
145
113
|
accumulateDispatches,
|
|
@@ -150,9 +118,6 @@ function accumulateEnterLeaveDispatches(leave, enter, fromID, toID) {
|
|
|
150
118
|
|
|
151
119
|
|
|
152
120
|
function accumulateDirectDispatches(events) {
|
|
153
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
154
|
-
injection.validate();
|
|
155
|
-
}
|
|
156
121
|
forEachAccumulated(events, accumulateDirectDispatchesSingle);
|
|
157
122
|
}
|
|
158
123
|
|
|
@@ -172,8 +137,7 @@ function accumulateDirectDispatches(events) {
|
|
|
172
137
|
var EventPropagators = {
|
|
173
138
|
accumulateTwoPhaseDispatches: accumulateTwoPhaseDispatches,
|
|
174
139
|
accumulateDirectDispatches: accumulateDirectDispatches,
|
|
175
|
-
accumulateEnterLeaveDispatches: accumulateEnterLeaveDispatches
|
|
176
|
-
injection: injection
|
|
140
|
+
accumulateEnterLeaveDispatches: accumulateEnterLeaveDispatches
|
|
177
141
|
};
|
|
178
142
|
|
|
179
143
|
module.exports = EventPropagators;
|
|
@@ -34,6 +34,9 @@ var ExecutionEnvironment = {
|
|
|
34
34
|
|
|
35
35
|
canUseWorkers: typeof Worker !== 'undefined',
|
|
36
36
|
|
|
37
|
+
canUseEventListeners:
|
|
38
|
+
canUseDOM && (window.addEventListener || window.attachEvent),
|
|
39
|
+
|
|
37
40
|
isInWorker: !canUseDOM // For now, this is true - might change in the future.
|
|
38
41
|
|
|
39
42
|
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 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 LinkedValueUtils
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var ReactPropTypes = require("./ReactPropTypes");
|
|
23
|
+
|
|
24
|
+
var invariant = require("./invariant");
|
|
25
|
+
|
|
26
|
+
var hasReadOnlyValue = {
|
|
27
|
+
'button': true,
|
|
28
|
+
'checkbox': true,
|
|
29
|
+
'image': true,
|
|
30
|
+
'hidden': true,
|
|
31
|
+
'radio': true,
|
|
32
|
+
'reset': true,
|
|
33
|
+
'submit': true
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function _assertSingleLink(input) {
|
|
37
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
38
|
+
input.props.checkedLink == null || input.props.valueLink == null,
|
|
39
|
+
'Cannot provide a checkedLink and a valueLink. If you want to use ' +
|
|
40
|
+
'checkedLink, you probably don\'t want to use valueLink and vice versa.'
|
|
41
|
+
) : invariant(input.props.checkedLink == null || input.props.valueLink == null));
|
|
42
|
+
}
|
|
43
|
+
function _assertValueLink(input) {
|
|
44
|
+
_assertSingleLink(input);
|
|
45
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
46
|
+
input.props.value == null && input.props.onChange == null,
|
|
47
|
+
'Cannot provide a valueLink and a value or onChange event. If you want ' +
|
|
48
|
+
'to use value or onChange, you probably don\'t want to use valueLink.'
|
|
49
|
+
) : invariant(input.props.value == null && input.props.onChange == null));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function _assertCheckedLink(input) {
|
|
53
|
+
_assertSingleLink(input);
|
|
54
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
55
|
+
input.props.checked == null && input.props.onChange == null,
|
|
56
|
+
'Cannot provide a checkedLink and a checked property or onChange event. ' +
|
|
57
|
+
'If you want to use checked or onChange, you probably don\'t want to ' +
|
|
58
|
+
'use checkedLink'
|
|
59
|
+
) : invariant(input.props.checked == null && input.props.onChange == null));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @param {SyntheticEvent} e change event to handle
|
|
64
|
+
*/
|
|
65
|
+
function _handleLinkedValueChange(e) {
|
|
66
|
+
/*jshint validthis:true */
|
|
67
|
+
this.props.valueLink.requestChange(e.target.value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {SyntheticEvent} e change event to handle
|
|
72
|
+
*/
|
|
73
|
+
function _handleLinkedCheckChange(e) {
|
|
74
|
+
/*jshint validthis:true */
|
|
75
|
+
this.props.checkedLink.requestChange(e.target.checked);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Provide a linked `value` attribute for controlled forms. You should not use
|
|
80
|
+
* this outside of the ReactDOM controlled form components.
|
|
81
|
+
*/
|
|
82
|
+
var LinkedValueUtils = {
|
|
83
|
+
Mixin: {
|
|
84
|
+
propTypes: {
|
|
85
|
+
value: function(props, propName, componentName) {
|
|
86
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
87
|
+
if (props[propName] &&
|
|
88
|
+
!hasReadOnlyValue[props.type] &&
|
|
89
|
+
!props.onChange &&
|
|
90
|
+
!props.readOnly &&
|
|
91
|
+
!props.disabled) {
|
|
92
|
+
console.warn(
|
|
93
|
+
'You provided a `value` prop to a form field without an ' +
|
|
94
|
+
'`onChange` handler. This will render a read-only field. If ' +
|
|
95
|
+
'the field should be mutable use `defaultValue`. Otherwise, ' +
|
|
96
|
+
'set either `onChange` or `readOnly`.'
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
checked: function(props, propName, componentName) {
|
|
102
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
103
|
+
if (props[propName] &&
|
|
104
|
+
!props.onChange &&
|
|
105
|
+
!props.readOnly &&
|
|
106
|
+
!props.disabled) {
|
|
107
|
+
console.warn(
|
|
108
|
+
'You provided a `checked` prop to a form field without an ' +
|
|
109
|
+
'`onChange` handler. This will render a read-only field. If ' +
|
|
110
|
+
'the field should be mutable use `defaultChecked`. Otherwise, ' +
|
|
111
|
+
'set either `onChange` or `readOnly`.'
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
onChange: ReactPropTypes.func
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @param {ReactComponent} input Form component
|
|
122
|
+
* @return {*} current value of the input either from value prop or link.
|
|
123
|
+
*/
|
|
124
|
+
getValue: function(input) {
|
|
125
|
+
if (input.props.valueLink) {
|
|
126
|
+
_assertValueLink(input);
|
|
127
|
+
return input.props.valueLink.value;
|
|
128
|
+
}
|
|
129
|
+
return input.props.value;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @param {ReactComponent} input Form component
|
|
134
|
+
* @return {*} current checked status of the input either from checked prop
|
|
135
|
+
* or link.
|
|
136
|
+
*/
|
|
137
|
+
getChecked: function(input) {
|
|
138
|
+
if (input.props.checkedLink) {
|
|
139
|
+
_assertCheckedLink(input);
|
|
140
|
+
return input.props.checkedLink.value;
|
|
141
|
+
}
|
|
142
|
+
return input.props.checked;
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @param {ReactComponent} input Form component
|
|
147
|
+
* @return {function} change callback either from onChange prop or link.
|
|
148
|
+
*/
|
|
149
|
+
getOnChange: function(input) {
|
|
150
|
+
if (input.props.valueLink) {
|
|
151
|
+
_assertValueLink(input);
|
|
152
|
+
return _handleLinkedValueChange;
|
|
153
|
+
} else if (input.props.checkedLink) {
|
|
154
|
+
_assertCheckedLink(input);
|
|
155
|
+
return _handleLinkedCheckChange;
|
|
156
|
+
}
|
|
157
|
+
return input.props.onChange;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
module.exports = LinkedValueUtils;
|