react 0.7.1 → 0.8.0
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 +15 -228
- package/ReactJSErrors.js +40 -0
- package/addons.js +4 -0
- package/lib/$.js +46 -0
- package/lib/CSSCore.js +114 -0
- package/lib/CSSProperty.js +90 -0
- package/lib/CSSPropertyOperations.js +97 -0
- package/lib/CallbackRegistry.js +91 -0
- package/lib/ChangeEventPlugin.js +365 -0
- package/lib/CompositionEventPlugin.js +212 -0
- package/lib/DOMChildrenOperations.js +135 -0
- package/lib/DOMProperty.js +266 -0
- package/lib/DOMPropertyOperations.js +168 -0
- package/lib/Danger.js +186 -0
- package/lib/DefaultDOMPropertyConfig.js +187 -0
- package/lib/DefaultEventPluginOrder.js +44 -0
- package/lib/EnterLeaveEventPlugin.js +112 -0
- package/lib/EventConstants.js +73 -0
- package/lib/EventListener.js +61 -0
- package/lib/EventPluginHub.js +190 -0
- package/lib/EventPluginRegistry.js +237 -0
- package/lib/EventPluginUtils.js +185 -0
- package/lib/EventPropagators.js +179 -0
- package/lib/ExecutionEnvironment.js +41 -0
- package/lib/LinkedStateMixin.js +46 -0
- package/lib/LinkedValueMixin.js +68 -0
- package/lib/MobileSafariClickEventPlugin.js +63 -0
- package/lib/PooledClass.js +113 -0
- package/lib/React.js +71 -0
- package/lib/ReactChildren.js +132 -0
- package/lib/ReactComponent.js +515 -0
- package/lib/ReactComponentBrowserEnvironment.js +140 -0
- package/lib/ReactComponentEnvironment.js +24 -0
- package/lib/ReactCompositeComponent.js +1020 -0
- package/lib/ReactCurrentOwner.js +39 -0
- package/lib/ReactDOM.js +194 -0
- package/lib/ReactDOMButton.js +64 -0
- package/lib/ReactDOMComponent.js +374 -0
- package/lib/ReactDOMForm.js +52 -0
- package/lib/ReactDOMIDOperations.js +173 -0
- package/lib/ReactDOMInput.js +169 -0
- package/lib/ReactDOMOption.js +50 -0
- package/lib/ReactDOMSelect.js +160 -0
- package/lib/ReactDOMSelection.js +189 -0
- package/lib/ReactDOMTextarea.js +136 -0
- package/lib/ReactDefaultBatchingStrategy.js +75 -0
- package/lib/ReactDefaultInjection.js +91 -0
- package/lib/ReactDefaultPerf.js +407 -0
- package/lib/ReactErrorUtils.js +46 -0
- package/lib/ReactEventEmitter.js +341 -0
- package/lib/ReactEventEmitterMixin.js +89 -0
- package/lib/ReactEventTopLevelCallback.js +89 -0
- package/lib/ReactInputSelection.js +140 -0
- package/lib/ReactInstanceHandles.js +322 -0
- package/lib/ReactLink.js +54 -0
- package/lib/ReactMarkupChecksum.js +53 -0
- package/lib/ReactMount.js +617 -0
- package/lib/ReactMountReady.js +95 -0
- package/lib/ReactMultiChild.js +441 -0
- package/lib/ReactMultiChildUpdateTypes.js +36 -0
- package/lib/ReactOwner.js +146 -0
- package/lib/ReactPerf.js +88 -0
- package/lib/ReactPropTransferer.js +128 -0
- package/lib/ReactPropTypes.js +158 -0
- package/lib/ReactReconcileTransaction.js +161 -0
- package/lib/ReactServerRendering.js +62 -0
- package/lib/ReactStateSetters.js +111 -0
- package/lib/ReactTextComponent.js +94 -0
- package/lib/ReactTransitionEvents.js +97 -0
- package/lib/ReactTransitionGroup.js +112 -0
- package/lib/ReactTransitionKeySet.js +111 -0
- package/lib/ReactTransitionableChild.js +152 -0
- package/lib/ReactUpdates.js +145 -0
- package/lib/ReactWithAddons.js +41 -0
- package/lib/SelectEventPlugin.js +217 -0
- package/lib/SimpleEventPlugin.js +365 -0
- package/lib/SyntheticClipboardEvent.js +45 -0
- package/lib/SyntheticCompositionEvent.js +51 -0
- package/lib/SyntheticEvent.js +163 -0
- package/lib/SyntheticFocusEvent.js +44 -0
- package/lib/SyntheticKeyboardEvent.js +56 -0
- package/lib/SyntheticMouseEvent.js +85 -0
- package/lib/SyntheticTouchEvent.js +50 -0
- package/lib/SyntheticUIEvent.js +45 -0
- package/lib/SyntheticWheelEvent.js +63 -0
- package/lib/Transaction.js +251 -0
- package/lib/ViewportMetrics.js +37 -0
- package/lib/accumulate.js +54 -0
- package/lib/adler32.js +39 -0
- package/lib/containsNode.js +49 -0
- package/lib/copyProperties.js +54 -0
- package/lib/createArrayFrom.js +94 -0
- package/lib/createNodesFromMarkup.js +93 -0
- package/lib/createObjectFrom.js +61 -0
- package/lib/cx.js +44 -0
- package/lib/dangerousStyleValue.js +57 -0
- package/lib/emptyFunction.js +43 -0
- package/lib/escapeTextForBrowser.js +47 -0
- package/lib/ex.js +49 -0
- package/lib/filterAttributes.js +45 -0
- package/lib/flattenChildren.js +54 -0
- package/lib/forEachAccumulated.js +36 -0
- package/lib/ge.js +76 -0
- package/lib/getActiveElement.js +33 -0
- package/lib/getEventTarget.js +36 -0
- package/lib/getMarkupWrap.js +108 -0
- package/lib/getNodeForCharacterOffset.js +80 -0
- package/lib/getReactRootElementInContainer.js +40 -0
- package/lib/getTextContentAccessor.js +40 -0
- package/lib/getUnboundedScrollPosition.js +45 -0
- package/lib/hyphenate.js +35 -0
- package/lib/invariant.js +54 -0
- package/lib/isEventSupported.js +74 -0
- package/lib/isNode.js +33 -0
- package/lib/isTextInputElement.js +49 -0
- package/lib/isTextNode.js +30 -0
- package/lib/joinClasses.js +44 -0
- package/lib/keyMirror.js +58 -0
- package/lib/keyOf.js +41 -0
- package/lib/memoizeStringOnly.js +39 -0
- package/lib/merge.js +37 -0
- package/lib/mergeHelpers.js +137 -0
- package/lib/mergeInto.js +45 -0
- package/lib/mixInto.js +34 -0
- package/lib/mutateHTMLNodeWithMarkup.js +100 -0
- package/lib/objMap.js +47 -0
- package/lib/objMapKeyVal.js +47 -0
- package/lib/performanceNow.js +42 -0
- package/lib/shallowEqual.js +49 -0
- package/lib/traverseAllChildren.js +127 -0
- package/package.json +33 -31
- package/react.js +4 -0
- package/.npmignore +0 -7
- package/.travis.yml +0 -7
- package/Jakefile.js +0 -39
- package/LICENSE +0 -19
- package/browser-test/dist.html +0 -90
- package/browser-test/index.html +0 -86
- package/browser-test/min.html +0 -90
- package/dist/react.js +0 -3141
- package/dist/react.min.js +0 -22
- package/doc/advanced.md +0 -175
- package/doc/color-def.graffle +0 -938
- package/doc/color-def.png +0 -0
- package/doc/simple.dot +0 -25
- package/doc/simple.png +0 -0
- package/examples/longer-example.js +0 -41
- package/examples/simple.js +0 -45
- package/examples/using-ast-directly.js +0 -30
- package/examples/using-events1.js +0 -79
- package/examples/using-log-events.js +0 -43
- package/lib/base-task.js +0 -120
- package/lib/cb-task.js +0 -84
- package/lib/core.js +0 -138
- package/lib/dsl.js +0 -138
- package/lib/error.js +0 -55
- package/lib/event-collector.js +0 -81
- package/lib/event-manager.js +0 -89
- package/lib/eventemitter.js +0 -20
- package/lib/finalcb-first-task.js +0 -68
- package/lib/finalcb-task.js +0 -65
- package/lib/id.js +0 -22
- package/lib/input-parser.js +0 -56
- package/lib/log-events.js +0 -101
- package/lib/parse.js +0 -41
- package/lib/promise-resolve.js +0 -50
- package/lib/promise-task.js +0 -93
- package/lib/react.js +0 -59
- package/lib/ret-task.js +0 -71
- package/lib/sprintf.js +0 -18
- package/lib/status.js +0 -14
- package/lib/task.js +0 -251
- package/lib/track-tasks.js +0 -74
- package/lib/validate.js +0 -159
- package/lib/vcon.js +0 -113
- package/lib/when-task.js +0 -84
- package/src/dist.build.requirejs +0 -20
- package/test/ast.mocha.js +0 -136
- package/test/cb-task.mocha.js +0 -220
- package/test/core-deferred.mocha.js +0 -143
- package/test/core-when.mocha.js +0 -96
- package/test/core.mocha.js +0 -589
- package/test/dsl.mocha.js +0 -352
- package/test/event-manager.mocha.js +0 -119
- package/test/exec-options.mocha.js +0 -48
- package/test/finalcb-task.mocha.js +0 -58
- package/test/input-parser.mocha.js +0 -86
- package/test/log-events.mocha.js +0 -88
- package/test/mocha.opts +0 -2
- package/test/module-use.mocha.js +0 -164
- package/test/promise-auto-resolve.mocha.js +0 -68
- package/test/ret-task.mocha.js +0 -220
- package/test/task.mocha.js +0 -42
- package/test/validate-cb-task.mocha.js +0 -100
- package/test/validate-ret-task.mocha.js +0 -110
- package/test/validate.mocha.js +0 -324
- package/test/vcon.mocha.js +0 -193
- package/vendor/chai/chai.js +0 -4251
- package/vendor/jquery/jquery-1.7.1.js +0 -9266
- package/vendor/jquery/jquery-1.7.1.min.js +0 -4
- package/vendor/node/util.js +0 -531
- package/vendor/requirejs/require.js +0 -2045
- package/vendor/requirejs/require.min.js +0 -36
|
@@ -0,0 +1,237 @@
|
|
|
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 EventPluginRegistry
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var invariant = require("./invariant");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Injectable ordering of event plugins.
|
|
26
|
+
*/
|
|
27
|
+
var EventPluginOrder = null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Injectable mapping from names to event plugin modules.
|
|
31
|
+
*/
|
|
32
|
+
var namesToPlugins = {};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Recomputes the plugin list using the injected plugins and plugin ordering.
|
|
36
|
+
*
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
function recomputePluginOrdering() {
|
|
40
|
+
if (!EventPluginOrder) {
|
|
41
|
+
// Wait until an `EventPluginOrder` is injected.
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
for (var pluginName in namesToPlugins) {
|
|
45
|
+
var PluginModule = namesToPlugins[pluginName];
|
|
46
|
+
var pluginIndex = EventPluginOrder.indexOf(pluginName);
|
|
47
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
48
|
+
pluginIndex > -1,
|
|
49
|
+
'EventPluginRegistry: Cannot inject event plugins that do not exist in ' +
|
|
50
|
+
'the plugin ordering, `%s`.',
|
|
51
|
+
pluginName
|
|
52
|
+
) : invariant(pluginIndex > -1));
|
|
53
|
+
if (EventPluginRegistry.plugins[pluginIndex]) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
57
|
+
PluginModule.extractEvents,
|
|
58
|
+
'EventPluginRegistry: Event plugins must implement an `extractEvents` ' +
|
|
59
|
+
'method, but `%s` does not.',
|
|
60
|
+
pluginName
|
|
61
|
+
) : invariant(PluginModule.extractEvents));
|
|
62
|
+
EventPluginRegistry.plugins[pluginIndex] = PluginModule;
|
|
63
|
+
var publishedEvents = PluginModule.eventTypes;
|
|
64
|
+
for (var eventName in publishedEvents) {
|
|
65
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
66
|
+
publishEventForPlugin(publishedEvents[eventName], PluginModule),
|
|
67
|
+
'EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.',
|
|
68
|
+
eventName,
|
|
69
|
+
pluginName
|
|
70
|
+
) : invariant(publishEventForPlugin(publishedEvents[eventName], PluginModule)));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Publishes an event so that it can be dispatched by the supplied plugin.
|
|
77
|
+
*
|
|
78
|
+
* @param {object} dispatchConfig Dispatch configuration for the event.
|
|
79
|
+
* @param {object} PluginModule Plugin publishing the event.
|
|
80
|
+
* @return {boolean} True if the event was successfully published.
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
function publishEventForPlugin(dispatchConfig, PluginModule) {
|
|
84
|
+
var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
|
|
85
|
+
if (phasedRegistrationNames) {
|
|
86
|
+
for (var phaseName in phasedRegistrationNames) {
|
|
87
|
+
if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
|
|
88
|
+
var phasedRegistrationName = phasedRegistrationNames[phaseName];
|
|
89
|
+
publishRegistrationName(phasedRegistrationName, PluginModule);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
} else if (dispatchConfig.registrationName) {
|
|
94
|
+
publishRegistrationName(dispatchConfig.registrationName, PluginModule);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Publishes a registration name that is used to identify dispatched events and
|
|
102
|
+
* can be used with `EventPluginHub.putListener` to register listeners.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} registrationName Registration name to add.
|
|
105
|
+
* @param {object} PluginModule Plugin publishing the event.
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
function publishRegistrationName(registrationName, PluginModule) {
|
|
109
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
110
|
+
!EventPluginRegistry.registrationNames[registrationName],
|
|
111
|
+
'EventPluginHub: More than one plugin attempted to publish the same ' +
|
|
112
|
+
'registration name, `%s`.',
|
|
113
|
+
registrationName
|
|
114
|
+
) : invariant(!EventPluginRegistry.registrationNames[registrationName]));
|
|
115
|
+
EventPluginRegistry.registrationNames[registrationName] = PluginModule;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Registers plugins so that they can extract and dispatch events.
|
|
120
|
+
*
|
|
121
|
+
* @see {EventPluginHub}
|
|
122
|
+
*/
|
|
123
|
+
var EventPluginRegistry = {
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Ordered list of injected plugins.
|
|
127
|
+
*/
|
|
128
|
+
plugins: [],
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Mapping from registration names to plugin modules.
|
|
132
|
+
*/
|
|
133
|
+
registrationNames: {},
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Injects an ordering of plugins (by plugin name). This allows the ordering
|
|
137
|
+
* to be decoupled from injection of the actual plugins so that ordering is
|
|
138
|
+
* always deterministic regardless of packaging, on-the-fly injection, etc.
|
|
139
|
+
*
|
|
140
|
+
* @param {array} InjectedEventPluginOrder
|
|
141
|
+
* @internal
|
|
142
|
+
* @see {EventPluginHub.injection.injectEventPluginOrder}
|
|
143
|
+
*/
|
|
144
|
+
injectEventPluginOrder: function(InjectedEventPluginOrder) {
|
|
145
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
146
|
+
!EventPluginOrder,
|
|
147
|
+
'EventPluginRegistry: Cannot inject event plugin ordering more than once.'
|
|
148
|
+
) : invariant(!EventPluginOrder));
|
|
149
|
+
// Clone the ordering so it cannot be dynamically mutated.
|
|
150
|
+
EventPluginOrder = Array.prototype.slice.call(InjectedEventPluginOrder);
|
|
151
|
+
recomputePluginOrdering();
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Injects plugins to be used by `EventPluginHub`. The plugin names must be
|
|
156
|
+
* in the ordering injected by `injectEventPluginOrder`.
|
|
157
|
+
*
|
|
158
|
+
* Plugins can be injected as part of page initialization or on-the-fly.
|
|
159
|
+
*
|
|
160
|
+
* @param {object} injectedNamesToPlugins Map from names to plugin modules.
|
|
161
|
+
* @internal
|
|
162
|
+
* @see {EventPluginHub.injection.injectEventPluginsByName}
|
|
163
|
+
*/
|
|
164
|
+
injectEventPluginsByName: function(injectedNamesToPlugins) {
|
|
165
|
+
var isOrderingDirty = false;
|
|
166
|
+
for (var pluginName in injectedNamesToPlugins) {
|
|
167
|
+
if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
var PluginModule = injectedNamesToPlugins[pluginName];
|
|
171
|
+
if (namesToPlugins[pluginName] !== PluginModule) {
|
|
172
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
173
|
+
!namesToPlugins[pluginName],
|
|
174
|
+
'EventPluginRegistry: Cannot inject two different event plugins ' +
|
|
175
|
+
'using the same name, `%s`.',
|
|
176
|
+
pluginName
|
|
177
|
+
) : invariant(!namesToPlugins[pluginName]));
|
|
178
|
+
namesToPlugins[pluginName] = PluginModule;
|
|
179
|
+
isOrderingDirty = true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (isOrderingDirty) {
|
|
183
|
+
recomputePluginOrdering();
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Looks up the plugin for the supplied event.
|
|
189
|
+
*
|
|
190
|
+
* @param {object} event A synthetic event.
|
|
191
|
+
* @return {?object} The plugin that created the supplied event.
|
|
192
|
+
* @internal
|
|
193
|
+
*/
|
|
194
|
+
getPluginModuleForEvent: function(event) {
|
|
195
|
+
var dispatchConfig = event.dispatchConfig;
|
|
196
|
+
if (dispatchConfig.registrationName) {
|
|
197
|
+
return EventPluginRegistry.registrationNames[
|
|
198
|
+
dispatchConfig.registrationName
|
|
199
|
+
] || null;
|
|
200
|
+
}
|
|
201
|
+
for (var phase in dispatchConfig.phasedRegistrationNames) {
|
|
202
|
+
if (!dispatchConfig.phasedRegistrationNames.hasOwnProperty(phase)) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
var PluginModule = EventPluginRegistry.registrationNames[
|
|
206
|
+
dispatchConfig.phasedRegistrationNames[phase]
|
|
207
|
+
];
|
|
208
|
+
if (PluginModule) {
|
|
209
|
+
return PluginModule;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Exposed for unit testing.
|
|
217
|
+
* @private
|
|
218
|
+
*/
|
|
219
|
+
_resetEventPlugins: function() {
|
|
220
|
+
EventPluginOrder = null;
|
|
221
|
+
for (var pluginName in namesToPlugins) {
|
|
222
|
+
if (namesToPlugins.hasOwnProperty(pluginName)) {
|
|
223
|
+
delete namesToPlugins[pluginName];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
EventPluginRegistry.plugins.length = 0;
|
|
227
|
+
var registrationNames = EventPluginRegistry.registrationNames;
|
|
228
|
+
for (var registrationName in registrationNames) {
|
|
229
|
+
if (registrationNames.hasOwnProperty(registrationName)) {
|
|
230
|
+
delete registrationNames[registrationName];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
module.exports = EventPluginRegistry;
|
|
@@ -0,0 +1,185 @@
|
|
|
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 EventPluginUtils
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var EventConstants = require("./EventConstants");
|
|
22
|
+
|
|
23
|
+
var invariant = require("./invariant");
|
|
24
|
+
|
|
25
|
+
var topLevelTypes = EventConstants.topLevelTypes;
|
|
26
|
+
|
|
27
|
+
function isEndish(topLevelType) {
|
|
28
|
+
return topLevelType === topLevelTypes.topMouseUp ||
|
|
29
|
+
topLevelType === topLevelTypes.topTouchEnd ||
|
|
30
|
+
topLevelType === topLevelTypes.topTouchCancel;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isMoveish(topLevelType) {
|
|
34
|
+
return topLevelType === topLevelTypes.topMouseMove ||
|
|
35
|
+
topLevelType === topLevelTypes.topTouchMove;
|
|
36
|
+
}
|
|
37
|
+
function isStartish(topLevelType) {
|
|
38
|
+
return topLevelType === topLevelTypes.topMouseDown ||
|
|
39
|
+
topLevelType === topLevelTypes.topTouchStart;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var validateEventDispatches;
|
|
43
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
44
|
+
validateEventDispatches = function(event) {
|
|
45
|
+
var dispatchListeners = event._dispatchListeners;
|
|
46
|
+
var dispatchIDs = event._dispatchIDs;
|
|
47
|
+
|
|
48
|
+
var listenersIsArr = Array.isArray(dispatchListeners);
|
|
49
|
+
var idsIsArr = Array.isArray(dispatchIDs);
|
|
50
|
+
var IDsLen = idsIsArr ? dispatchIDs.length : dispatchIDs ? 1 : 0;
|
|
51
|
+
var listenersLen = listenersIsArr ?
|
|
52
|
+
dispatchListeners.length :
|
|
53
|
+
dispatchListeners ? 1 : 0;
|
|
54
|
+
|
|
55
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
56
|
+
idsIsArr === listenersIsArr && IDsLen === listenersLen,
|
|
57
|
+
'EventPluginUtils: Invalid `event`.'
|
|
58
|
+
) : invariant(idsIsArr === listenersIsArr && IDsLen === listenersLen));
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Invokes `cb(event, listener, id)`. Avoids using call if no scope is
|
|
64
|
+
* provided. The `(listener,id)` pair effectively forms the "dispatch" but are
|
|
65
|
+
* kept separate to conserve memory.
|
|
66
|
+
*/
|
|
67
|
+
function forEachEventDispatch(event, cb) {
|
|
68
|
+
var dispatchListeners = event._dispatchListeners;
|
|
69
|
+
var dispatchIDs = event._dispatchIDs;
|
|
70
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
71
|
+
validateEventDispatches(event);
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(dispatchListeners)) {
|
|
74
|
+
for (var i = 0; i < dispatchListeners.length; i++) {
|
|
75
|
+
if (event.isPropagationStopped()) {
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
// Listeners and IDs are two parallel arrays that are always in sync.
|
|
79
|
+
cb(event, dispatchListeners[i], dispatchIDs[i]);
|
|
80
|
+
}
|
|
81
|
+
} else if (dispatchListeners) {
|
|
82
|
+
cb(event, dispatchListeners, dispatchIDs);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Default implementation of PluginModule.executeDispatch().
|
|
88
|
+
* @param {SyntheticEvent} SyntheticEvent to handle
|
|
89
|
+
* @param {function} Application-level callback
|
|
90
|
+
* @param {string} domID DOM id to pass to the callback.
|
|
91
|
+
*/
|
|
92
|
+
function executeDispatch(event, listener, domID) {
|
|
93
|
+
listener(event, domID);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Standard/simple iteration through an event's collected dispatches.
|
|
98
|
+
*/
|
|
99
|
+
function executeDispatchesInOrder(event, executeDispatch) {
|
|
100
|
+
forEachEventDispatch(event, executeDispatch);
|
|
101
|
+
event._dispatchListeners = null;
|
|
102
|
+
event._dispatchIDs = null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Standard/simple iteration through an event's collected dispatches, but stops
|
|
107
|
+
* at the first dispatch execution returning true, and returns that id.
|
|
108
|
+
*
|
|
109
|
+
* @return id of the first dispatch execution who's listener returns true, or
|
|
110
|
+
* null if no listener returned true.
|
|
111
|
+
*/
|
|
112
|
+
function executeDispatchesInOrderStopAtTrue(event) {
|
|
113
|
+
var dispatchListeners = event._dispatchListeners;
|
|
114
|
+
var dispatchIDs = event._dispatchIDs;
|
|
115
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
116
|
+
validateEventDispatches(event);
|
|
117
|
+
}
|
|
118
|
+
if (Array.isArray(dispatchListeners)) {
|
|
119
|
+
for (var i = 0; i < dispatchListeners.length; i++) {
|
|
120
|
+
if (event.isPropagationStopped()) {
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
// Listeners and IDs are two parallel arrays that are always in sync.
|
|
124
|
+
if (dispatchListeners[i](event, dispatchIDs[i])) {
|
|
125
|
+
return dispatchIDs[i];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
} else if (dispatchListeners) {
|
|
129
|
+
if (dispatchListeners(event, dispatchIDs)) {
|
|
130
|
+
return dispatchIDs;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Execution of a "direct" dispatch - there must be at most one dispatch
|
|
138
|
+
* accumulated on the event or it is considered an error. It doesn't really make
|
|
139
|
+
* sense for an event with multiple dispatches (bubbled) to keep track of the
|
|
140
|
+
* return values at each dispatch execution, but it does tend to make sense when
|
|
141
|
+
* dealing with "direct" dispatches.
|
|
142
|
+
*
|
|
143
|
+
* @return The return value of executing the single dispatch.
|
|
144
|
+
*/
|
|
145
|
+
function executeDirectDispatch(event) {
|
|
146
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
147
|
+
validateEventDispatches(event);
|
|
148
|
+
}
|
|
149
|
+
var dispatchListener = event._dispatchListeners;
|
|
150
|
+
var dispatchID = event._dispatchIDs;
|
|
151
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
152
|
+
!Array.isArray(dispatchListener),
|
|
153
|
+
'executeDirectDispatch(...): Invalid `event`.'
|
|
154
|
+
) : invariant(!Array.isArray(dispatchListener)));
|
|
155
|
+
var res = dispatchListener ?
|
|
156
|
+
dispatchListener(event, dispatchID) :
|
|
157
|
+
null;
|
|
158
|
+
event._dispatchListeners = null;
|
|
159
|
+
event._dispatchIDs = null;
|
|
160
|
+
return res;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @param {SyntheticEvent} event
|
|
165
|
+
* @return {bool} True iff number of dispatches accumulated is greater than 0.
|
|
166
|
+
*/
|
|
167
|
+
function hasDispatches(event) {
|
|
168
|
+
return !!event._dispatchListeners;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* General utilities that are useful in creating custom Event Plugins.
|
|
173
|
+
*/
|
|
174
|
+
var EventPluginUtils = {
|
|
175
|
+
isEndish: isEndish,
|
|
176
|
+
isMoveish: isMoveish,
|
|
177
|
+
isStartish: isStartish,
|
|
178
|
+
executeDispatchesInOrder: executeDispatchesInOrder,
|
|
179
|
+
executeDispatchesInOrderStopAtTrue: executeDispatchesInOrderStopAtTrue,
|
|
180
|
+
executeDirectDispatch: executeDirectDispatch,
|
|
181
|
+
hasDispatches: hasDispatches,
|
|
182
|
+
executeDispatch: executeDispatch
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
module.exports = EventPluginUtils;
|
|
@@ -0,0 +1,179 @@
|
|
|
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 EventPropagators
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var CallbackRegistry = require("./CallbackRegistry");
|
|
22
|
+
var EventConstants = require("./EventConstants");
|
|
23
|
+
|
|
24
|
+
var accumulate = require("./accumulate");
|
|
25
|
+
var forEachAccumulated = require("./forEachAccumulated");
|
|
26
|
+
var getListener = CallbackRegistry.getListener;
|
|
27
|
+
var PropagationPhases = EventConstants.PropagationPhases;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Injected dependencies:
|
|
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
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Some event types have a notion of different registration names for different
|
|
57
|
+
* "phases" of propagation. This finds listeners by a given phase.
|
|
58
|
+
*/
|
|
59
|
+
function listenerAtPhase(id, event, propagationPhase) {
|
|
60
|
+
var registrationName =
|
|
61
|
+
event.dispatchConfig.phasedRegistrationNames[propagationPhase];
|
|
62
|
+
return getListener(id, registrationName);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Tags a `SyntheticEvent` with dispatched listeners. Creating this function
|
|
67
|
+
* here, allows us to not have to bind or create functions for each event.
|
|
68
|
+
* Mutating the event's members allows us to not have to create a wrapping
|
|
69
|
+
* "dispatch" object that pairs the event with the listener.
|
|
70
|
+
*/
|
|
71
|
+
function accumulateDirectionalDispatches(domID, upwards, event) {
|
|
72
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
73
|
+
if (!domID) {
|
|
74
|
+
throw new Error('Dispatching id must not be null');
|
|
75
|
+
}
|
|
76
|
+
injection.validate();
|
|
77
|
+
}
|
|
78
|
+
var phase = upwards ? PropagationPhases.bubbled : PropagationPhases.captured;
|
|
79
|
+
var listener = listenerAtPhase(domID, event, phase);
|
|
80
|
+
if (listener) {
|
|
81
|
+
event._dispatchListeners = accumulate(event._dispatchListeners, listener);
|
|
82
|
+
event._dispatchIDs = accumulate(event._dispatchIDs, domID);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Collect dispatches (must be entirely collected before dispatching - see unit
|
|
88
|
+
* tests). Lazily allocate the array to conserve memory. We must loop through
|
|
89
|
+
* each event and perform the traversal for each one. We can not perform a
|
|
90
|
+
* single traversal for the entire collection of events because each event may
|
|
91
|
+
* have a different target.
|
|
92
|
+
*/
|
|
93
|
+
function accumulateTwoPhaseDispatchesSingle(event) {
|
|
94
|
+
if (event && event.dispatchConfig.phasedRegistrationNames) {
|
|
95
|
+
injection.InstanceHandle.traverseTwoPhase(
|
|
96
|
+
event.dispatchMarker,
|
|
97
|
+
accumulateDirectionalDispatches,
|
|
98
|
+
event
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Accumulates without regard to direction, does not look for phased
|
|
106
|
+
* registration names. Same as `accumulateDirectDispatchesSingle` but without
|
|
107
|
+
* requiring that the `dispatchMarker` be the same as the dispatched ID.
|
|
108
|
+
*/
|
|
109
|
+
function accumulateDispatches(id, ignoredDirection, event) {
|
|
110
|
+
if (event && event.dispatchConfig.registrationName) {
|
|
111
|
+
var registrationName = event.dispatchConfig.registrationName;
|
|
112
|
+
var listener = getListener(id, registrationName);
|
|
113
|
+
if (listener) {
|
|
114
|
+
event._dispatchListeners = accumulate(event._dispatchListeners, listener);
|
|
115
|
+
event._dispatchIDs = accumulate(event._dispatchIDs, id);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Accumulates dispatches on an `SyntheticEvent`, but only for the
|
|
122
|
+
* `dispatchMarker`.
|
|
123
|
+
* @param {SyntheticEvent} event
|
|
124
|
+
*/
|
|
125
|
+
function accumulateDirectDispatchesSingle(event) {
|
|
126
|
+
if (event && event.dispatchConfig.registrationName) {
|
|
127
|
+
accumulateDispatches(event.dispatchMarker, null, event);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function accumulateTwoPhaseDispatches(events) {
|
|
132
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
133
|
+
injection.validate();
|
|
134
|
+
}
|
|
135
|
+
forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function accumulateEnterLeaveDispatches(leave, enter, fromID, toID) {
|
|
139
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
140
|
+
injection.validate();
|
|
141
|
+
}
|
|
142
|
+
injection.InstanceHandle.traverseEnterLeave(
|
|
143
|
+
fromID,
|
|
144
|
+
toID,
|
|
145
|
+
accumulateDispatches,
|
|
146
|
+
leave,
|
|
147
|
+
enter
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
function accumulateDirectDispatches(events) {
|
|
153
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
154
|
+
injection.validate();
|
|
155
|
+
}
|
|
156
|
+
forEachAccumulated(events, accumulateDirectDispatchesSingle);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* A small set of propagation patterns, each of which will accept a small amount
|
|
163
|
+
* of information, and generate a set of "dispatch ready event objects" - which
|
|
164
|
+
* are sets of events that have already been annotated with a set of dispatched
|
|
165
|
+
* listener functions/ids. The API is designed this way to discourage these
|
|
166
|
+
* propagation strategies from actually executing the dispatches, since we
|
|
167
|
+
* always want to collect the entire set of dispatches before executing event a
|
|
168
|
+
* single one.
|
|
169
|
+
*
|
|
170
|
+
* @constructor EventPropagators
|
|
171
|
+
*/
|
|
172
|
+
var EventPropagators = {
|
|
173
|
+
accumulateTwoPhaseDispatches: accumulateTwoPhaseDispatches,
|
|
174
|
+
accumulateDirectDispatches: accumulateDirectDispatches,
|
|
175
|
+
accumulateEnterLeaveDispatches: accumulateEnterLeaveDispatches,
|
|
176
|
+
injection: injection
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
module.exports = EventPropagators;
|