react 0.6.3 → 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 +10 -222
- package/addons.js +1 -0
- package/lib/AutoFocusMixin.js +30 -0
- package/lib/CSSCore.js +115 -0
- package/lib/CSSProperty.js +121 -0
- package/lib/CSSPropertyOperations.js +97 -0
- package/lib/ChangeEventPlugin.js +387 -0
- package/lib/ClientReactRootIndex.js +30 -0
- package/lib/CompositionEventPlugin.js +260 -0
- package/lib/DOMChildrenOperations.js +165 -0
- package/lib/DOMProperty.js +268 -0
- package/lib/DOMPropertyOperations.js +181 -0
- package/lib/Danger.js +187 -0
- package/lib/DefaultDOMPropertyConfig.js +197 -0
- package/lib/DefaultEventPluginOrder.js +44 -0
- package/lib/EnterLeaveEventPlugin.js +145 -0
- package/lib/EventConstants.js +76 -0
- package/lib/EventListener.js +69 -0
- package/lib/EventPluginHub.js +291 -0
- package/lib/EventPluginRegistry.js +260 -0
- package/lib/EventPluginUtils.js +214 -0
- package/lib/EventPropagators.js +143 -0
- package/lib/ExecutionEnvironment.js +44 -0
- package/lib/LinkedStateMixin.js +46 -0
- package/lib/LinkedValueUtils.js +161 -0
- package/lib/MobileSafariClickEventPlugin.js +63 -0
- package/lib/PooledClass.js +119 -0
- package/lib/React.js +95 -0
- package/lib/ReactCSSTransitionGroup.js +65 -0
- package/lib/ReactCSSTransitionGroupChild.js +138 -0
- package/lib/ReactChildren.js +132 -0
- package/lib/ReactComponent.js +550 -0
- package/lib/ReactComponentBrowserEnvironment.js +158 -0
- package/lib/ReactComponentEnvironment.js +26 -0
- package/lib/ReactCompositeComponent.js +1455 -0
- package/lib/ReactContext.js +67 -0
- package/lib/ReactCurrentOwner.js +39 -0
- package/lib/ReactDOM.js +207 -0
- package/lib/ReactDOMButton.js +68 -0
- package/lib/ReactDOMComponent.js +399 -0
- package/lib/ReactDOMForm.js +59 -0
- package/lib/ReactDOMIDOperations.js +218 -0
- package/lib/ReactDOMImg.js +58 -0
- package/lib/ReactDOMInput.js +181 -0
- package/lib/ReactDOMOption.js +51 -0
- package/lib/ReactDOMSelect.js +179 -0
- package/lib/ReactDOMSelection.js +189 -0
- package/lib/ReactDOMTextarea.js +140 -0
- package/lib/ReactDefaultBatchingStrategy.js +75 -0
- package/lib/ReactDefaultInjection.js +115 -0
- package/lib/ReactDefaultPerf.js +244 -0
- package/lib/ReactDefaultPerfAnalysis.js +199 -0
- package/lib/ReactErrorUtils.js +37 -0
- package/lib/ReactEventEmitter.js +337 -0
- package/lib/ReactEventEmitterMixin.js +57 -0
- package/lib/ReactEventTopLevelCallback.js +109 -0
- package/lib/ReactInjection.js +39 -0
- package/lib/ReactInputSelection.js +140 -0
- package/lib/ReactInstanceHandles.js +338 -0
- package/lib/ReactLink.js +54 -0
- package/lib/ReactMarkupChecksum.js +53 -0
- package/lib/ReactMount.js +641 -0
- package/lib/ReactMountReady.js +95 -0
- package/lib/ReactMultiChild.js +425 -0
- package/lib/ReactMultiChildUpdateTypes.js +38 -0
- package/lib/ReactOwner.js +154 -0
- package/lib/ReactPerf.js +85 -0
- package/lib/ReactPropTransferer.js +147 -0
- package/lib/ReactPropTypeLocationNames.js +31 -0
- package/lib/ReactPropTypeLocations.js +29 -0
- package/lib/ReactPropTypes.js +359 -0
- package/lib/ReactPutListenerQueue.js +61 -0
- package/lib/ReactReconcileTransaction.js +181 -0
- package/lib/ReactRootIndex.js +36 -0
- package/lib/ReactServerRendering.js +59 -0
- package/lib/ReactStateSetters.js +111 -0
- package/lib/ReactTextComponent.js +99 -0
- package/lib/ReactTransitionChildMapping.js +106 -0
- package/lib/ReactTransitionEvents.js +97 -0
- package/lib/ReactTransitionGroup.js +187 -0
- package/lib/ReactUpdates.js +148 -0
- package/lib/ReactWithAddons.js +46 -0
- package/lib/SelectEventPlugin.js +200 -0
- package/lib/ServerReactRootIndex.js +36 -0
- package/lib/SimpleEventPlugin.js +413 -0
- package/lib/SyntheticClipboardEvent.js +51 -0
- package/lib/SyntheticCompositionEvent.js +51 -0
- package/lib/SyntheticDragEvent.js +44 -0
- package/lib/SyntheticEvent.js +164 -0
- package/lib/SyntheticFocusEvent.js +44 -0
- package/lib/SyntheticKeyboardEvent.js +58 -0
- package/lib/SyntheticMouseEvent.js +85 -0
- package/lib/SyntheticTouchEvent.js +50 -0
- package/lib/SyntheticUIEvent.js +45 -0
- package/lib/SyntheticWheelEvent.js +66 -0
- package/lib/Transaction.js +276 -0
- package/lib/ViewportMetrics.js +37 -0
- package/lib/accumulate.js +54 -0
- package/lib/adler32.js +39 -0
- package/lib/cloneWithProps.js +59 -0
- package/lib/containsNode.js +49 -0
- package/lib/copyProperties.js +54 -0
- package/lib/createArrayFrom.js +91 -0
- package/lib/createFullPageComponent.js +63 -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/flattenChildren.js +57 -0
- package/lib/forEachAccumulated.js +36 -0
- package/lib/getActiveElement.js +34 -0
- package/lib/getEventKey.js +85 -0
- package/lib/getEventTarget.js +36 -0
- package/lib/getMarkupWrap.js +118 -0
- package/lib/getNodeForCharacterOffset.js +80 -0
- package/lib/getReactRootElementInContainer.js +40 -0
- package/lib/getTextContentAccessor.js +42 -0
- package/lib/getUnboundedScrollPosition.js +45 -0
- package/lib/hyphenate.js +35 -0
- package/lib/invariant.js +62 -0
- package/lib/isEventSupported.js +70 -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 +136 -0
- package/lib/mergeInto.js +45 -0
- package/lib/mixInto.js +34 -0
- package/lib/objMap.js +47 -0
- package/lib/objMapKeyVal.js +47 -0
- package/lib/onlyChild.js +43 -0
- package/lib/performanceNow.js +42 -0
- package/lib/shallowEqual.js +49 -0
- package/lib/shouldUpdateReactComponent.js +58 -0
- package/lib/toArray.js +75 -0
- package/lib/traverseAllChildren.js +189 -0
- package/lib/warning.js +40 -0
- package/package.json +32 -21
- package/react.js +1 -0
- package/.npmignore +0 -7
- package/.travis.yml +0 -5
- 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 -3107
- package/dist/react.min.js +0 -22
- package/doc/advanced.md +0 -174
- 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 -123
- 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 -90
- package/lib/when-task.js +0 -85
- 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 -350
- 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 -147
- 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 -2038
- package/vendor/jquery/jquery-1.7.1.js +0 -9266
- package/vendor/jquery/jquery-1.7.1.min.js +0 -4
- package/vendor/mocha/mocha.css +0 -135
- package/vendor/mocha/mocha.js +0 -3589
- package/vendor/node/util.js +0 -531
- package/vendor/requirejs/require.js +0 -2053
- package/vendor/requirejs/require.min.js +0 -33
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @providesModule EventListener
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
var emptyFunction = require("./emptyFunction");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Upstream version of event listener. Does not take into account specific
|
|
9
|
+
* nature of platform.
|
|
10
|
+
*/
|
|
11
|
+
var EventListener = {
|
|
12
|
+
/**
|
|
13
|
+
* Listen to DOM events during the bubble phase.
|
|
14
|
+
*
|
|
15
|
+
* @param {DOMEventTarget} target DOM element to register listener on.
|
|
16
|
+
* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
|
|
17
|
+
* @param {function} callback Callback function.
|
|
18
|
+
* @return {object} Object with a `remove` method.
|
|
19
|
+
*/
|
|
20
|
+
listen: function(target, eventType, callback) {
|
|
21
|
+
if (target.addEventListener) {
|
|
22
|
+
target.addEventListener(eventType, callback, false);
|
|
23
|
+
return {
|
|
24
|
+
remove: function() {
|
|
25
|
+
target.removeEventListener(eventType, callback, false);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
} else if (target.attachEvent) {
|
|
29
|
+
target.attachEvent('on' + eventType, callback);
|
|
30
|
+
return {
|
|
31
|
+
remove: function() {
|
|
32
|
+
target.detachEvent(eventType, callback);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Listen to DOM events during the capture phase.
|
|
40
|
+
*
|
|
41
|
+
* @param {DOMEventTarget} target DOM element to register listener on.
|
|
42
|
+
* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
|
|
43
|
+
* @param {function} callback Callback function.
|
|
44
|
+
* @return {object} Object with a `remove` method.
|
|
45
|
+
*/
|
|
46
|
+
capture: function(target, eventType, callback) {
|
|
47
|
+
if (!target.addEventListener) {
|
|
48
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
49
|
+
console.error(
|
|
50
|
+
'Attempted to listen to events during the capture phase on a ' +
|
|
51
|
+
'browser that does not support the capture phase. Your application ' +
|
|
52
|
+
'will not receive some events.'
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
remove: emptyFunction
|
|
57
|
+
};
|
|
58
|
+
} else {
|
|
59
|
+
target.addEventListener(eventType, callback, true);
|
|
60
|
+
return {
|
|
61
|
+
remove: function() {
|
|
62
|
+
target.removeEventListener(eventType, callback, true);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
module.exports = EventListener;
|
|
@@ -0,0 +1,291 @@
|
|
|
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 EventPluginHub
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var EventPluginRegistry = require("./EventPluginRegistry");
|
|
22
|
+
var EventPluginUtils = require("./EventPluginUtils");
|
|
23
|
+
var ExecutionEnvironment = require("./ExecutionEnvironment");
|
|
24
|
+
|
|
25
|
+
var accumulate = require("./accumulate");
|
|
26
|
+
var forEachAccumulated = require("./forEachAccumulated");
|
|
27
|
+
var invariant = require("./invariant");
|
|
28
|
+
var isEventSupported = require("./isEventSupported");
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Internal store for event listeners
|
|
32
|
+
*/
|
|
33
|
+
var listenerBank = {};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Internal queue of events that have accumulated their dispatches and are
|
|
37
|
+
* waiting to have their dispatches executed.
|
|
38
|
+
*/
|
|
39
|
+
var eventQueue = null;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Dispatches an event and releases it back into the pool, unless persistent.
|
|
43
|
+
*
|
|
44
|
+
* @param {?object} event Synthetic event to be dispatched.
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
var executeDispatchesAndRelease = function(event) {
|
|
48
|
+
if (event) {
|
|
49
|
+
var executeDispatch = EventPluginUtils.executeDispatch;
|
|
50
|
+
// Plugins can provide custom behavior when dispatching events.
|
|
51
|
+
var PluginModule = EventPluginRegistry.getPluginModuleForEvent(event);
|
|
52
|
+
if (PluginModule && PluginModule.executeDispatch) {
|
|
53
|
+
executeDispatch = PluginModule.executeDispatch;
|
|
54
|
+
}
|
|
55
|
+
EventPluginUtils.executeDispatchesInOrder(event, executeDispatch);
|
|
56
|
+
|
|
57
|
+
if (!event.isPersistent()) {
|
|
58
|
+
event.constructor.release(event);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* - `InstanceHandle`: [required] Module that performs logical traversals of DOM
|
|
65
|
+
* hierarchy given ids of the logical DOM elements involved.
|
|
66
|
+
*/
|
|
67
|
+
var InstanceHandle = null;
|
|
68
|
+
|
|
69
|
+
function validateInstanceHandle() {
|
|
70
|
+
var invalid = !InstanceHandle||
|
|
71
|
+
!InstanceHandle.traverseTwoPhase ||
|
|
72
|
+
!InstanceHandle.traverseEnterLeave;
|
|
73
|
+
if (invalid) {
|
|
74
|
+
throw new Error('InstanceHandle not injected before use!');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* This is a unified interface for event plugins to be installed and configured.
|
|
80
|
+
*
|
|
81
|
+
* Event plugins can implement the following properties:
|
|
82
|
+
*
|
|
83
|
+
* `extractEvents` {function(string, DOMEventTarget, string, object): *}
|
|
84
|
+
* Required. When a top-level event is fired, this method is expected to
|
|
85
|
+
* extract synthetic events that will in turn be queued and dispatched.
|
|
86
|
+
*
|
|
87
|
+
* `eventTypes` {object}
|
|
88
|
+
* Optional, plugins that fire events must publish a mapping of registration
|
|
89
|
+
* names that are used to register listeners. Values of this mapping must
|
|
90
|
+
* be objects that contain `registrationName` or `phasedRegistrationNames`.
|
|
91
|
+
*
|
|
92
|
+
* `executeDispatch` {function(object, function, string)}
|
|
93
|
+
* Optional, allows plugins to override how an event gets dispatched. By
|
|
94
|
+
* default, the listener is simply invoked.
|
|
95
|
+
*
|
|
96
|
+
* Each plugin that is injected into `EventsPluginHub` is immediately operable.
|
|
97
|
+
*
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
var EventPluginHub = {
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Methods for injecting dependencies.
|
|
104
|
+
*/
|
|
105
|
+
injection: {
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {object} InjectedMount
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
injectMount: EventPluginUtils.injection.injectMount,
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @param {object} InjectedInstanceHandle
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
injectInstanceHandle: function(InjectedInstanceHandle) {
|
|
118
|
+
InstanceHandle = InjectedInstanceHandle;
|
|
119
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
120
|
+
validateInstanceHandle();
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
getInstanceHandle: function() {
|
|
125
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
126
|
+
validateInstanceHandle();
|
|
127
|
+
}
|
|
128
|
+
return InstanceHandle;
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @param {array} InjectedEventPluginOrder
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
injectEventPluginOrder: EventPluginRegistry.injectEventPluginOrder,
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @param {object} injectedNamesToPlugins Map from names to plugin modules.
|
|
139
|
+
*/
|
|
140
|
+
injectEventPluginsByName: EventPluginRegistry.injectEventPluginsByName
|
|
141
|
+
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
registrationNameModules: EventPluginRegistry.registrationNameModules,
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Stores `listener` at `listenerBank[registrationName][id]`. Is idempotent.
|
|
148
|
+
*
|
|
149
|
+
* @param {string} id ID of the DOM element.
|
|
150
|
+
* @param {string} registrationName Name of listener (e.g. `onClick`).
|
|
151
|
+
* @param {?function} listener The callback to store.
|
|
152
|
+
*/
|
|
153
|
+
putListener: function(id, registrationName, listener) {
|
|
154
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
155
|
+
ExecutionEnvironment.canUseDOM,
|
|
156
|
+
'Cannot call putListener() in a non-DOM environment.'
|
|
157
|
+
) : invariant(ExecutionEnvironment.canUseDOM));
|
|
158
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
159
|
+
!listener || typeof listener === 'function',
|
|
160
|
+
'Expected %s listener to be a function, instead got type %s',
|
|
161
|
+
registrationName, typeof listener
|
|
162
|
+
) : invariant(!listener || typeof listener === 'function'));
|
|
163
|
+
|
|
164
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
165
|
+
// IE8 has no API for event capturing and the `onScroll` event doesn't
|
|
166
|
+
// bubble.
|
|
167
|
+
if (registrationName === 'onScroll' &&
|
|
168
|
+
!isEventSupported('scroll', true)) {
|
|
169
|
+
console.warn('This browser doesn\'t support the `onScroll` event');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
var bankForRegistrationName =
|
|
173
|
+
listenerBank[registrationName] || (listenerBank[registrationName] = {});
|
|
174
|
+
bankForRegistrationName[id] = listener;
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @param {string} id ID of the DOM element.
|
|
179
|
+
* @param {string} registrationName Name of listener (e.g. `onClick`).
|
|
180
|
+
* @return {?function} The stored callback.
|
|
181
|
+
*/
|
|
182
|
+
getListener: function(id, registrationName) {
|
|
183
|
+
var bankForRegistrationName = listenerBank[registrationName];
|
|
184
|
+
return bankForRegistrationName && bankForRegistrationName[id];
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Deletes a listener from the registration bank.
|
|
189
|
+
*
|
|
190
|
+
* @param {string} id ID of the DOM element.
|
|
191
|
+
* @param {string} registrationName Name of listener (e.g. `onClick`).
|
|
192
|
+
*/
|
|
193
|
+
deleteListener: function(id, registrationName) {
|
|
194
|
+
var bankForRegistrationName = listenerBank[registrationName];
|
|
195
|
+
if (bankForRegistrationName) {
|
|
196
|
+
delete bankForRegistrationName[id];
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Deletes all listeners for the DOM element with the supplied ID.
|
|
202
|
+
*
|
|
203
|
+
* @param {string} id ID of the DOM element.
|
|
204
|
+
*/
|
|
205
|
+
deleteAllListeners: function(id) {
|
|
206
|
+
for (var registrationName in listenerBank) {
|
|
207
|
+
delete listenerBank[registrationName][id];
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Allows registered plugins an opportunity to extract events from top-level
|
|
213
|
+
* native browser events.
|
|
214
|
+
*
|
|
215
|
+
* @param {string} topLevelType Record from `EventConstants`.
|
|
216
|
+
* @param {DOMEventTarget} topLevelTarget The listening component root node.
|
|
217
|
+
* @param {string} topLevelTargetID ID of `topLevelTarget`.
|
|
218
|
+
* @param {object} nativeEvent Native browser event.
|
|
219
|
+
* @return {*} An accumulation of synthetic events.
|
|
220
|
+
* @internal
|
|
221
|
+
*/
|
|
222
|
+
extractEvents: function(
|
|
223
|
+
topLevelType,
|
|
224
|
+
topLevelTarget,
|
|
225
|
+
topLevelTargetID,
|
|
226
|
+
nativeEvent) {
|
|
227
|
+
var events;
|
|
228
|
+
var plugins = EventPluginRegistry.plugins;
|
|
229
|
+
for (var i = 0, l = plugins.length; i < l; i++) {
|
|
230
|
+
// Not every plugin in the ordering may be loaded at runtime.
|
|
231
|
+
var possiblePlugin = plugins[i];
|
|
232
|
+
if (possiblePlugin) {
|
|
233
|
+
var extractedEvents = possiblePlugin.extractEvents(
|
|
234
|
+
topLevelType,
|
|
235
|
+
topLevelTarget,
|
|
236
|
+
topLevelTargetID,
|
|
237
|
+
nativeEvent
|
|
238
|
+
);
|
|
239
|
+
if (extractedEvents) {
|
|
240
|
+
events = accumulate(events, extractedEvents);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return events;
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Enqueues a synthetic event that should be dispatched when
|
|
249
|
+
* `processEventQueue` is invoked.
|
|
250
|
+
*
|
|
251
|
+
* @param {*} events An accumulation of synthetic events.
|
|
252
|
+
* @internal
|
|
253
|
+
*/
|
|
254
|
+
enqueueEvents: function(events) {
|
|
255
|
+
if (events) {
|
|
256
|
+
eventQueue = accumulate(eventQueue, events);
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Dispatches all synthetic events on the event queue.
|
|
262
|
+
*
|
|
263
|
+
* @internal
|
|
264
|
+
*/
|
|
265
|
+
processEventQueue: function() {
|
|
266
|
+
// Set `eventQueue` to null before processing it so that we can tell if more
|
|
267
|
+
// events get enqueued while processing.
|
|
268
|
+
var processingEventQueue = eventQueue;
|
|
269
|
+
eventQueue = null;
|
|
270
|
+
forEachAccumulated(processingEventQueue, executeDispatchesAndRelease);
|
|
271
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
272
|
+
!eventQueue,
|
|
273
|
+
'processEventQueue(): Additional events were enqueued while processing ' +
|
|
274
|
+
'an event queue. Support for this has not yet been implemented.'
|
|
275
|
+
) : invariant(!eventQueue));
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* These are needed for tests only. Do not use!
|
|
280
|
+
*/
|
|
281
|
+
__purge: function() {
|
|
282
|
+
listenerBank = {};
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
__getListenerBank: function() {
|
|
286
|
+
return listenerBank;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
module.exports = EventPluginHub;
|
|
@@ -0,0 +1,260 @@
|
|
|
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(
|
|
67
|
+
publishedEvents[eventName],
|
|
68
|
+
PluginModule,
|
|
69
|
+
eventName
|
|
70
|
+
),
|
|
71
|
+
'EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.',
|
|
72
|
+
eventName,
|
|
73
|
+
pluginName
|
|
74
|
+
) : invariant(publishEventForPlugin(
|
|
75
|
+
publishedEvents[eventName],
|
|
76
|
+
PluginModule,
|
|
77
|
+
eventName
|
|
78
|
+
)));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Publishes an event so that it can be dispatched by the supplied plugin.
|
|
85
|
+
*
|
|
86
|
+
* @param {object} dispatchConfig Dispatch configuration for the event.
|
|
87
|
+
* @param {object} PluginModule Plugin publishing the event.
|
|
88
|
+
* @return {boolean} True if the event was successfully published.
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
function publishEventForPlugin(dispatchConfig, PluginModule, eventName) {
|
|
92
|
+
var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
|
|
93
|
+
if (phasedRegistrationNames) {
|
|
94
|
+
for (var phaseName in phasedRegistrationNames) {
|
|
95
|
+
if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
|
|
96
|
+
var phasedRegistrationName = phasedRegistrationNames[phaseName];
|
|
97
|
+
publishRegistrationName(
|
|
98
|
+
phasedRegistrationName,
|
|
99
|
+
PluginModule,
|
|
100
|
+
eventName
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
} else if (dispatchConfig.registrationName) {
|
|
106
|
+
publishRegistrationName(
|
|
107
|
+
dispatchConfig.registrationName,
|
|
108
|
+
PluginModule,
|
|
109
|
+
eventName
|
|
110
|
+
);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Publishes a registration name that is used to identify dispatched events and
|
|
118
|
+
* can be used with `EventPluginHub.putListener` to register listeners.
|
|
119
|
+
*
|
|
120
|
+
* @param {string} registrationName Registration name to add.
|
|
121
|
+
* @param {object} PluginModule Plugin publishing the event.
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
function publishRegistrationName(registrationName, PluginModule, eventName) {
|
|
125
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
126
|
+
!EventPluginRegistry.registrationNameModules[registrationName],
|
|
127
|
+
'EventPluginHub: More than one plugin attempted to publish the same ' +
|
|
128
|
+
'registration name, `%s`.',
|
|
129
|
+
registrationName
|
|
130
|
+
) : invariant(!EventPluginRegistry.registrationNameModules[registrationName]));
|
|
131
|
+
EventPluginRegistry.registrationNameModules[registrationName] = PluginModule;
|
|
132
|
+
EventPluginRegistry.registrationNameDependencies[registrationName] =
|
|
133
|
+
PluginModule.eventTypes[eventName].dependencies;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Registers plugins so that they can extract and dispatch events.
|
|
138
|
+
*
|
|
139
|
+
* @see {EventPluginHub}
|
|
140
|
+
*/
|
|
141
|
+
var EventPluginRegistry = {
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Ordered list of injected plugins.
|
|
145
|
+
*/
|
|
146
|
+
plugins: [],
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Mapping from registration names to plugin modules.
|
|
150
|
+
*/
|
|
151
|
+
registrationNameModules: {},
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Mapping from registration name to event name
|
|
155
|
+
*/
|
|
156
|
+
registrationNameDependencies: {},
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Injects an ordering of plugins (by plugin name). This allows the ordering
|
|
160
|
+
* to be decoupled from injection of the actual plugins so that ordering is
|
|
161
|
+
* always deterministic regardless of packaging, on-the-fly injection, etc.
|
|
162
|
+
*
|
|
163
|
+
* @param {array} InjectedEventPluginOrder
|
|
164
|
+
* @internal
|
|
165
|
+
* @see {EventPluginHub.injection.injectEventPluginOrder}
|
|
166
|
+
*/
|
|
167
|
+
injectEventPluginOrder: function(InjectedEventPluginOrder) {
|
|
168
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
169
|
+
!EventPluginOrder,
|
|
170
|
+
'EventPluginRegistry: Cannot inject event plugin ordering more than once.'
|
|
171
|
+
) : invariant(!EventPluginOrder));
|
|
172
|
+
// Clone the ordering so it cannot be dynamically mutated.
|
|
173
|
+
EventPluginOrder = Array.prototype.slice.call(InjectedEventPluginOrder);
|
|
174
|
+
recomputePluginOrdering();
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Injects plugins to be used by `EventPluginHub`. The plugin names must be
|
|
179
|
+
* in the ordering injected by `injectEventPluginOrder`.
|
|
180
|
+
*
|
|
181
|
+
* Plugins can be injected as part of page initialization or on-the-fly.
|
|
182
|
+
*
|
|
183
|
+
* @param {object} injectedNamesToPlugins Map from names to plugin modules.
|
|
184
|
+
* @internal
|
|
185
|
+
* @see {EventPluginHub.injection.injectEventPluginsByName}
|
|
186
|
+
*/
|
|
187
|
+
injectEventPluginsByName: function(injectedNamesToPlugins) {
|
|
188
|
+
var isOrderingDirty = false;
|
|
189
|
+
for (var pluginName in injectedNamesToPlugins) {
|
|
190
|
+
if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
var PluginModule = injectedNamesToPlugins[pluginName];
|
|
194
|
+
if (namesToPlugins[pluginName] !== PluginModule) {
|
|
195
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
196
|
+
!namesToPlugins[pluginName],
|
|
197
|
+
'EventPluginRegistry: Cannot inject two different event plugins ' +
|
|
198
|
+
'using the same name, `%s`.',
|
|
199
|
+
pluginName
|
|
200
|
+
) : invariant(!namesToPlugins[pluginName]));
|
|
201
|
+
namesToPlugins[pluginName] = PluginModule;
|
|
202
|
+
isOrderingDirty = true;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (isOrderingDirty) {
|
|
206
|
+
recomputePluginOrdering();
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Looks up the plugin for the supplied event.
|
|
212
|
+
*
|
|
213
|
+
* @param {object} event A synthetic event.
|
|
214
|
+
* @return {?object} The plugin that created the supplied event.
|
|
215
|
+
* @internal
|
|
216
|
+
*/
|
|
217
|
+
getPluginModuleForEvent: function(event) {
|
|
218
|
+
var dispatchConfig = event.dispatchConfig;
|
|
219
|
+
if (dispatchConfig.registrationName) {
|
|
220
|
+
return EventPluginRegistry.registrationNameModules[
|
|
221
|
+
dispatchConfig.registrationName
|
|
222
|
+
] || null;
|
|
223
|
+
}
|
|
224
|
+
for (var phase in dispatchConfig.phasedRegistrationNames) {
|
|
225
|
+
if (!dispatchConfig.phasedRegistrationNames.hasOwnProperty(phase)) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
var PluginModule = EventPluginRegistry.registrationNameModules[
|
|
229
|
+
dispatchConfig.phasedRegistrationNames[phase]
|
|
230
|
+
];
|
|
231
|
+
if (PluginModule) {
|
|
232
|
+
return PluginModule;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Exposed for unit testing.
|
|
240
|
+
* @private
|
|
241
|
+
*/
|
|
242
|
+
_resetEventPlugins: function() {
|
|
243
|
+
EventPluginOrder = null;
|
|
244
|
+
for (var pluginName in namesToPlugins) {
|
|
245
|
+
if (namesToPlugins.hasOwnProperty(pluginName)) {
|
|
246
|
+
delete namesToPlugins[pluginName];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
EventPluginRegistry.plugins.length = 0;
|
|
250
|
+
var registrationNameModules = EventPluginRegistry.registrationNameModules;
|
|
251
|
+
for (var registrationName in registrationNameModules) {
|
|
252
|
+
if (registrationNameModules.hasOwnProperty(registrationName)) {
|
|
253
|
+
delete registrationNameModules[registrationName];
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
module.exports = EventPluginRegistry;
|