@samitouri / QOS-React-2 / commits / 92b7b172cc

Use named exports in more places (#11457)

* Convert EventPlugin{Hub,Registry} to named exports * Convert EventPluginUtils to named exports * Convert EventPropagators to named exports * Convert ReactControlledComponent to named exports * Convert ReactGenericBatching to named exports * Convert ReactDOMComponentTree to named exports * Convert ReactNativeComponentTree to named exports * Convert ReactNativeRTComponentTree to named exports * Convert FallbackCompositionState to named exports * Convert ReactEventEmitterMixin to named exports * Convert ReactBrowserEventEmitter to named exports * Convert ReactNativeEventEmitter to named exports * Convert ReactDOMEventListener to named exports * Convert DOMMarkupOperations to named exports * Convert DOMProperty to named exports * Add suppression for existing Flow violation Flow didn't see it before. * Update sizes

Dan Abramov committed Nov 5, 2017 at 11:58 UTC 92b7b172cce9958b846844f0b46fd7bbd8c5140d
56 files changed +1071 -1358
packages/events/EventPluginHub.js
+122 -119
@@ -8,8 +8,15 @@
8 import ReactErrorUtils from 'shared/ReactErrorUtils';
9 import invariant from 'fbjs/lib/invariant';
10
11 -import EventPluginRegistry from './EventPluginRegistry';
12 -import EventPluginUtils from './EventPluginUtils';
11 +import {
12 + injectEventPluginOrder,
13 + injectEventPluginsByName,
14 + plugins,
15 +} from './EventPluginRegistry';
16 +import {
17 + executeDispatchesInOrder,
18 + getFiberCurrentPropsFromNode,
19 +} from './EventPluginUtils';
20 import accumulateInto from './accumulateInto';
21 import forEachAccumulated from './forEachAccumulated';
22
@@ -28,7 +35,7 @@ var eventQueue = null;
35 */
36 var executeDispatchesAndRelease = function(event, simulated) {
37 if (event) {
31 - EventPluginUtils.executeDispatchesInOrder(event, simulated);
38 + executeDispatchesInOrder(event, simulated);
39
40 if (!event.isPersistent()) {
41 event.constructor.release(event);
@@ -91,131 +98,127 @@ function shouldPreventMouseEvent(name, type, props) {
98 *
99 * @public
100 */
94 -var EventPluginHub = {
101 +
102 +/**
103 + * Methods for injecting dependencies.
104 + */
105 +export const injection = {
106 /**
96 - * Methods for injecting dependencies.
107 + * @param {array} InjectedEventPluginOrder
108 + * @public
109 */
98 - injection: {
99 - /**
100 - * @param {array} InjectedEventPluginOrder
101 - * @public
102 - */
103 - injectEventPluginOrder: EventPluginRegistry.injectEventPluginOrder,
104 -
105 - /**
106 - * @param {object} injectedNamesToPlugins Map from names to plugin modules.
107 - */
108 - injectEventPluginsByName: EventPluginRegistry.injectEventPluginsByName,
109 - },
110 + injectEventPluginOrder,
111
112 /**
112 - * @param {object} inst The instance, which is the source of events.
113 - * @param {string} registrationName Name of listener (e.g. `onClick`).
114 - * @return {?function} The stored callback.
113 + * @param {object} injectedNamesToPlugins Map from names to plugin modules.
114 */
116 - getListener: function(inst, registrationName) {
117 - var listener;
115 + injectEventPluginsByName,
116 +};
117
119 - // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
120 - // live here; needs to be moved to a better place soon
121 - const stateNode = inst.stateNode;
122 - if (!stateNode) {
123 - // Work in progress (ex: onload events in incremental mode).
124 - return null;
125 - }
126 - const props = EventPluginUtils.getFiberCurrentPropsFromNode(stateNode);
127 - if (!props) {
128 - // Work in progress.
129 - return null;
130 - }
131 - listener = props[registrationName];
132 - if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
133 - return null;
134 - }
135 - invariant(
136 - !listener || typeof listener === 'function',
137 - 'Expected `%s` listener to be a function, instead got a value of `%s` type.',
138 - registrationName,
139 - typeof listener,
140 - );
141 - return listener;
142 - },
118 +/**
119 + * @param {object} inst The instance, which is the source of events.
120 + * @param {string} registrationName Name of listener (e.g. `onClick`).
121 + * @return {?function} The stored callback.
122 + */
123 +export function getListener(inst, registrationName) {
124 + var listener;
125
144 - /**
145 - * Allows registered plugins an opportunity to extract events from top-level
146 - * native browser events.
147 - *
148 - * @return {*} An accumulation of synthetic events.
149 - * @internal
150 - */
151 - extractEvents: function(
152 - topLevelType,
153 - targetInst,
154 - nativeEvent,
155 - nativeEventTarget,
156 - ) {
157 - var events;
158 - var plugins = EventPluginRegistry.plugins;
159 - for (var i = 0; i < plugins.length; i++) {
160 - // Not every plugin in the ordering may be loaded at runtime.
161 - var possiblePlugin = plugins[i];
162 - if (possiblePlugin) {
163 - var extractedEvents = possiblePlugin.extractEvents(
164 - topLevelType,
165 - targetInst,
166 - nativeEvent,
167 - nativeEventTarget,
168 - );
169 - if (extractedEvents) {
170 - events = accumulateInto(events, extractedEvents);
171 - }
126 + // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
127 + // live here; needs to be moved to a better place soon
128 + const stateNode = inst.stateNode;
129 + if (!stateNode) {
130 + // Work in progress (ex: onload events in incremental mode).
131 + return null;
132 + }
133 + const props = getFiberCurrentPropsFromNode(stateNode);
134 + if (!props) {
135 + // Work in progress.
136 + return null;
137 + }
138 + listener = props[registrationName];
139 + if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
140 + return null;
141 + }
142 + invariant(
143 + !listener || typeof listener === 'function',
144 + 'Expected `%s` listener to be a function, instead got a value of `%s` type.',
145 + registrationName,
146 + typeof listener,
147 + );
148 + return listener;
149 +}
150 +
151 +/**
152 + * Allows registered plugins an opportunity to extract events from top-level
153 + * native browser events.
154 + *
155 + * @return {*} An accumulation of synthetic events.
156 + * @internal
157 + */
158 +export function extractEvents(
159 + topLevelType,
160 + targetInst,
161 + nativeEvent,
162 + nativeEventTarget,
163 +) {
164 + var events;
165 + for (var i = 0; i < plugins.length; i++) {
166 + // Not every plugin in the ordering may be loaded at runtime.
167 + var possiblePlugin = plugins[i];
168 + if (possiblePlugin) {
169 + var extractedEvents = possiblePlugin.extractEvents(
170 + topLevelType,
171 + targetInst,
172 + nativeEvent,
173 + nativeEventTarget,
174 + );
175 + if (extractedEvents) {
176 + events = accumulateInto(events, extractedEvents);
177 }
178 }
174 - return events;
175 - },
179 + }
180 + return events;
181 +}
182
177 - /**
178 - * Enqueues a synthetic event that should be dispatched when
179 - * `processEventQueue` is invoked.
180 - *
181 - * @param {*} events An accumulation of synthetic events.
182 - * @internal
183 - */
184 - enqueueEvents: function(events) {
185 - if (events) {
186 - eventQueue = accumulateInto(eventQueue, events);
187 - }
188 - },
183 +/**
184 + * Enqueues a synthetic event that should be dispatched when
185 + * `processEventQueue` is invoked.
186 + *
187 + * @param {*} events An accumulation of synthetic events.
188 + * @internal
189 + */
190 +export function enqueueEvents(events) {
191 + if (events) {
192 + eventQueue = accumulateInto(eventQueue, events);
193 + }
194 +}
195
190 - /**
191 - * Dispatches all synthetic events on the event queue.
192 - *
193 - * @internal
194 - */
195 - processEventQueue: function(simulated) {
196 - // Set `eventQueue` to null before processing it so that we can tell if more
197 - // events get enqueued while processing.
198 - var processingEventQueue = eventQueue;
199 - eventQueue = null;
200 - if (simulated) {
201 - forEachAccumulated(
202 - processingEventQueue,
203 - executeDispatchesAndReleaseSimulated,
204 - );
205 - } else {
206 - forEachAccumulated(
207 - processingEventQueue,
208 - executeDispatchesAndReleaseTopLevel,
209 - );
210 - }
211 - invariant(
212 - !eventQueue,
213 - 'processEventQueue(): Additional events were enqueued while processing ' +
214 - 'an event queue. Support for this has not yet been implemented.',
196 +/**
197 + * Dispatches all synthetic events on the event queue.
198 + *
199 + * @internal
200 + */
201 +export function processEventQueue(simulated) {
202 + // Set `eventQueue` to null before processing it so that we can tell if more
203 + // events get enqueued while processing.
204 + var processingEventQueue = eventQueue;
205 + eventQueue = null;
206 + if (simulated) {
207 + forEachAccumulated(
208 + processingEventQueue,
209 + executeDispatchesAndReleaseSimulated,
210 );
216 - // This would be a good time to rethrow if any of the event handlers threw.
217 - ReactErrorUtils.rethrowCaughtError();
218 - },
219 -};
220 -
221 -export default EventPluginHub;
211 + } else {
212 + forEachAccumulated(
213 + processingEventQueue,
214 + executeDispatchesAndReleaseTopLevel,
215 + );
216 + }
217 + invariant(
218 + !eventQueue,
219 + 'processEventQueue(): Additional events were enqueued while processing ' +
220 + 'an event queue. Support for this has not yet been implemented.',
221 + );
222 + // This would be a good time to rethrow if any of the event handlers threw.
223 + ReactErrorUtils.rethrowCaughtError();
224 +}
packages/events/EventPluginRegistry.js
+96 -101
@@ -48,7 +48,7 @@ function recomputePluginOrdering(): void {
48 'the plugin ordering, `%s`.',
49 pluginName,
50 );
51 - if (EventPluginRegistry.plugins[pluginIndex]) {
51 + if (plugins[pluginIndex]) {
52 continue;
53 }
54 invariant(
@@ -57,7 +57,7 @@ function recomputePluginOrdering(): void {
57 'method, but `%s` does not.',
58 pluginName,
59 );
60 - EventPluginRegistry.plugins[pluginIndex] = pluginModule;
60 + plugins[pluginIndex] = pluginModule;
61 var publishedEvents = pluginModule.eventTypes;
62 for (var eventName in publishedEvents) {
63 invariant(
@@ -88,12 +88,12 @@ function publishEventForPlugin(
88 eventName: string,
89 ): boolean {
90 invariant(
91 - !EventPluginRegistry.eventNameDispatchConfigs.hasOwnProperty(eventName),
91 + !eventNameDispatchConfigs.hasOwnProperty(eventName),
92 'EventPluginHub: More than one plugin attempted to publish the same ' +
93 'event name, `%s`.',
94 eventName,
95 );
96 - EventPluginRegistry.eventNameDispatchConfigs[eventName] = dispatchConfig;
96 + eventNameDispatchConfigs[eventName] = dispatchConfig;
97
98 var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
99 if (phasedRegistrationNames) {
@@ -132,23 +132,21 @@ function publishRegistrationName(
132 eventName: string,
133 ): void {
134 invariant(
135 - !EventPluginRegistry.registrationNameModules[registrationName],
135 + !registrationNameModules[registrationName],
136 'EventPluginHub: More than one plugin attempted to publish the same ' +
137 'registration name, `%s`.',
138 registrationName,
139 );
140 - EventPluginRegistry.registrationNameModules[registrationName] = pluginModule;
141 - EventPluginRegistry.registrationNameDependencies[registrationName] =
140 + registrationNameModules[registrationName] = pluginModule;
141 + registrationNameDependencies[registrationName] =
142 pluginModule.eventTypes[eventName].dependencies;
143
144 if (__DEV__) {
145 var lowerCasedName = registrationName.toLowerCase();
146 - EventPluginRegistry.possibleRegistrationNames[
147 - lowerCasedName
148 - ] = registrationName;
146 + possibleRegistrationNames[lowerCasedName] = registrationName;
147
148 if (registrationName === 'onDoubleClick') {
151 - EventPluginRegistry.possibleRegistrationNames.ondblclick = registrationName;
149 + possibleRegistrationNames.ondblclick = registrationName;
150 }
151 }
152 }
@@ -158,95 +156,92 @@ function publishRegistrationName(
156 *
157 * @see {EventPluginHub}
158 */
161 -var EventPluginRegistry = {
162 - /**
163 - * Ordered list of injected plugins.
164 - */
165 - plugins: [],
166 -
167 - /**
168 - * Mapping from event name to dispatch config
169 - */
170 - eventNameDispatchConfigs: {},
171 -
172 - /**
173 - * Mapping from registration name to plugin module
174 - */
175 - registrationNameModules: {},
176 -
177 - /**
178 - * Mapping from registration name to event name
179 - */
180 - registrationNameDependencies: {},
181 -
182 - /**
183 - * Mapping from lowercase registration names to the properly cased version,
184 - * used to warn in the case of missing event handlers. Available
185 - * only in __DEV__.
186 - * @type {Object}
187 - */
188 - possibleRegistrationNames: __DEV__ ? {} : (null: any),
189 - // Trust the developer to only use possibleRegistrationNames in __DEV__
190 -
191 - /**
192 - * Injects an ordering of plugins (by plugin name). This allows the ordering
193 - * to be decoupled from injection of the actual plugins so that ordering is
194 - * always deterministic regardless of packaging, on-the-fly injection, etc.
195 - *
196 - * @param {array} InjectedEventPluginOrder
197 - * @internal
198 - * @see {EventPluginHub.injection.injectEventPluginOrder}
199 - */
200 - injectEventPluginOrder: function(
201 - injectedEventPluginOrder: EventPluginOrder,
202 - ): void {
203 - invariant(
204 - !eventPluginOrder,
205 - 'EventPluginRegistry: Cannot inject event plugin ordering more than ' +
206 - 'once. You are likely trying to load more than one copy of React.',
207 - );
208 - // Clone the ordering so it cannot be dynamically mutated.
209 - eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder);
210 - recomputePluginOrdering();
211 - },
212 -
213 - /**
214 - * Injects plugins to be used by `EventPluginHub`. The plugin names must be
215 - * in the ordering injected by `injectEventPluginOrder`.
216 - *
217 - * Plugins can be injected as part of page initialization or on-the-fly.
218 - *
219 - * @param {object} injectedNamesToPlugins Map from names to plugin modules.
220 - * @internal
221 - * @see {EventPluginHub.injection.injectEventPluginsByName}
222 - */
223 - injectEventPluginsByName: function(
224 - injectedNamesToPlugins: NamesToPlugins,
225 - ): void {
226 - var isOrderingDirty = false;
227 - for (var pluginName in injectedNamesToPlugins) {
228 - if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
229 - continue;
230 - }
231 - var pluginModule = injectedNamesToPlugins[pluginName];
232 - if (
233 - !namesToPlugins.hasOwnProperty(pluginName) ||
234 - namesToPlugins[pluginName] !== pluginModule
235 - ) {
236 - invariant(
237 - !namesToPlugins[pluginName],
238 - 'EventPluginRegistry: Cannot inject two different event plugins ' +
239 - 'using the same name, `%s`.',
240 - pluginName,
241 - );
242 - namesToPlugins[pluginName] = pluginModule;
243 - isOrderingDirty = true;
244 - }
159 +
160 +/**
161 + * Ordered list of injected plugins.
162 + */
163 +export const plugins = [];
164 +
165 +/**
166 + * Mapping from event name to dispatch config
167 + */
168 +export const eventNameDispatchConfigs = {};
169 +
170 +/**
171 + * Mapping from registration name to plugin module
172 + */
173 +export const registrationNameModules = {};
174 +
175 +/**
176 + * Mapping from registration name to event name
177 + */
178 +export const registrationNameDependencies = {};
179 +
180 +/**
181 + * Mapping from lowercase registration names to the properly cased version,
182 + * used to warn in the case of missing event handlers. Available
183 + * only in __DEV__.
184 + * @type {Object}
185 + */
186 +export const possibleRegistrationNames = __DEV__ ? {} : (null: any);
187 +// Trust the developer to only use possibleRegistrationNames in __DEV__
188 +
189 +/**
190 + * Injects an ordering of plugins (by plugin name). This allows the ordering
191 + * to be decoupled from injection of the actual plugins so that ordering is
192 + * always deterministic regardless of packaging, on-the-fly injection, etc.
193 + *
194 + * @param {array} InjectedEventPluginOrder
195 + * @internal
196 + * @see {EventPluginHub.injection.injectEventPluginOrder}
197 + */
198 +export function injectEventPluginOrder(
199 + injectedEventPluginOrder: EventPluginOrder,
200 +): void {
201 + invariant(
202 + !eventPluginOrder,
203 + 'EventPluginRegistry: Cannot inject event plugin ordering more than ' +
204 + 'once. You are likely trying to load more than one copy of React.',
205 + );
206 + // Clone the ordering so it cannot be dynamically mutated.
207 + eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder);
208 + recomputePluginOrdering();
209 +}
210 +
211 +/**
212 + * Injects plugins to be used by `EventPluginHub`. The plugin names must be
213 + * in the ordering injected by `injectEventPluginOrder`.
214 + *
215 + * Plugins can be injected as part of page initialization or on-the-fly.
216 + *
217 + * @param {object} injectedNamesToPlugins Map from names to plugin modules.
218 + * @internal
219 + * @see {EventPluginHub.injection.injectEventPluginsByName}
220 + */
221 +export function injectEventPluginsByName(
222 + injectedNamesToPlugins: NamesToPlugins,
223 +): void {
224 + var isOrderingDirty = false;
225 + for (var pluginName in injectedNamesToPlugins) {
226 + if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
227 + continue;
228 }
246 - if (isOrderingDirty) {
247 - recomputePluginOrdering();
229 + var pluginModule = injectedNamesToPlugins[pluginName];
230 + if (
231 + !namesToPlugins.hasOwnProperty(pluginName) ||
232 + namesToPlugins[pluginName] !== pluginModule
233 + ) {
234 + invariant(
235 + !namesToPlugins[pluginName],
236 + 'EventPluginRegistry: Cannot inject two different event plugins ' +
237 + 'using the same name, `%s`.',
238 + pluginName,
239 + );
240 + namesToPlugins[pluginName] = pluginModule;
241 + isOrderingDirty = true;
242 }
249 - },
250 -};
251 -
252 -export default EventPluginRegistry;
243 + }
244 + if (isOrderingDirty) {
245 + recomputePluginOrdering();
246 + }
247 +}
packages/events/EventPluginUtils.js
+19 -50
@@ -9,23 +9,20 @@ import ReactErrorUtils from 'shared/ReactErrorUtils';
9 import invariant from 'fbjs/lib/invariant';
10 import warning from 'fbjs/lib/warning';
11
12 -/**
13 - * Injected dependencies:
14 - */
12 +export let getFiberCurrentPropsFromNode = null;
13 +export let getInstanceFromNode = null;
14 +export let getNodeFromInstance = null;
15
16 -/**
17 - * - `ComponentTree`: [required] Module that can convert between React instances
18 - * and actual node references.
19 - */
20 -var ComponentTree;
21 -var injection = {
16 +export const injection = {
17 injectComponentTree: function(Injected) {
23 - ComponentTree = Injected;
18 + ({
19 + getFiberCurrentPropsFromNode,
20 + getInstanceFromNode,
21 + getNodeFromInstance,
22 + } = Injected);
23 if (__DEV__) {
24 warning(
26 - Injected &&
27 - Injected.getNodeFromInstance &&
28 - Injected.getInstanceFromNode,
25 + getNodeFromInstance && getInstanceFromNode,
26 'EventPluginUtils.injection.injectComponentTree(...): Injected ' +
27 'module is missing getNodeFromInstance or getInstanceFromNode.',
28 );
@@ -33,7 +30,7 @@ var injection = {
30 },
31 };
32
36 -function isEndish(topLevelType) {
33 +export function isEndish(topLevelType) {
34 return (
35 topLevelType === 'topMouseUp' ||
36 topLevelType === 'topTouchEnd' ||
@@ -41,10 +38,10 @@ function isEndish(topLevelType) {
38 );
39 }
40
44 -function isMoveish(topLevelType) {
41 +export function isMoveish(topLevelType) {
42 return topLevelType === 'topMouseMove' || topLevelType === 'topTouchMove';
43 }
47 -function isStartish(topLevelType) {
44 +export function isStartish(topLevelType) {
45 return topLevelType === 'topMouseDown' || topLevelType === 'topTouchStart';
46 }
47
@@ -80,7 +77,7 @@ if (__DEV__) {
77 */
78 function executeDispatch(event, simulated, listener, inst) {
79 var type = event.type || 'unknown-event';
83 - event.currentTarget = EventPluginUtils.getNodeFromInstance(inst);
80 + event.currentTarget = getNodeFromInstance(inst);
81 ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError(
82 type,
83 listener,
@@ -93,7 +90,7 @@ function executeDispatch(event, simulated, listener, inst) {
90 /**
91 * Standard/simple iteration through an event's collected dispatches.
92 */
96 -function executeDispatchesInOrder(event, simulated) {
93 +export function executeDispatchesInOrder(event, simulated) {
94 var dispatchListeners = event._dispatchListeners;
95 var dispatchInstances = event._dispatchInstances;
96 if (__DEV__) {
@@ -153,7 +150,7 @@ function executeDispatchesInOrderStopAtTrueImpl(event) {
150 /**
151 * @see executeDispatchesInOrderStopAtTrueImpl
152 */
156 -function executeDispatchesInOrderStopAtTrue(event) {
153 +export function executeDispatchesInOrderStopAtTrue(event) {
154 var ret = executeDispatchesInOrderStopAtTrueImpl(event);
155 event._dispatchInstances = null;
156 event._dispatchListeners = null;
@@ -169,7 +166,7 @@ function executeDispatchesInOrderStopAtTrue(event) {
166 *
167 * @return {*} The return value of executing the single dispatch.
168 */
172 -function executeDirectDispatch(event) {
169 +export function executeDirectDispatch(event) {
170 if (__DEV__) {
171 validateEventDispatches(event);
172 }
@@ -180,7 +177,7 @@ function executeDirectDispatch(event) {
177 'executeDirectDispatch(...): Invalid `event`.',
178 );
179 event.currentTarget = dispatchListener
183 - ? EventPluginUtils.getNodeFromInstance(dispatchInstance)
180 + ? getNodeFromInstance(dispatchInstance)
181 : null;
182 var res = dispatchListener ? dispatchListener(event) : null;
183 event.currentTarget = null;
@@ -193,34 +190,6 @@ function executeDirectDispatch(event) {
190 * @param {SyntheticEvent} event
191 * @return {boolean} True iff number of dispatches accumulated is greater than 0.
192 */
196 -function hasDispatches(event) {
193 +export function hasDispatches(event) {
194 return !!event._dispatchListeners;
195 }
199 -
200 -/**
201 - * General utilities that are useful in creating custom Event Plugins.
202 - */
203 -var EventPluginUtils = {
204 - isEndish: isEndish,
205 - isMoveish: isMoveish,
206 - isStartish: isStartish,
207 -
208 - executeDirectDispatch: executeDirectDispatch,
209 - executeDispatchesInOrder: executeDispatchesInOrder,
210 - executeDispatchesInOrderStopAtTrue: executeDispatchesInOrderStopAtTrue,
211 - hasDispatches: hasDispatches,
212 -
213 - getFiberCurrentPropsFromNode: function(node) {
214 - return ComponentTree.getFiberCurrentPropsFromNode(node);
215 - },
216 - getInstanceFromNode: function(node) {
217 - return ComponentTree.getInstanceFromNode(node);
218 - },
219 - getNodeFromInstance: function(node) {
220 - return ComponentTree.getNodeFromInstance(node);
221 - },
222 -
223 - injection: injection,
224 -};
225 -
226 -export default EventPluginUtils;
packages/events/EventPropagators.js
+15 -27
@@ -12,14 +12,12 @@ import {
12 } from 'shared/ReactTreeTraversal';
13 import warning from 'fbjs/lib/warning';
14
15 -import EventPluginHub from './EventPluginHub';
15 +import {getListener} from './EventPluginHub';
16 import accumulateInto from './accumulateInto';
17 import forEachAccumulated from './forEachAccumulated';
18
19 type PropagationPhases = 'bubbled' | 'captured';
20
21 -var getListener = EventPluginHub.getListener;
22 -
21 /**
22 * Some event types have a notion of different registration names for different
23 * "phases" of propagation. This finds listeners by a given phase.
@@ -30,6 +28,16 @@ function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) {
28 return getListener(inst, registrationName);
29 }
30
31 +/**
32 + * A small set of propagation patterns, each of which will accept a small amount
33 + * of information, and generate a set of "dispatch ready event objects" - which
34 + * are sets of events that have already been annotated with a set of dispatched
35 + * listener functions/ids. The API is designed this way to discourage these
36 + * propagation strategies from actually executing the dispatches, since we
37 + * always want to collect the entire set of dispatches before executing even a
38 + * single one.
39 + */
40 +
41 /**
42 * Tags a `SyntheticEvent` with dispatched listeners. Creating this function
43 * here, allows us to not have to bind or create functions for each event.
@@ -104,38 +112,18 @@ function accumulateDirectDispatchesSingle(event) {
112 }
113 }
114
107 -function accumulateTwoPhaseDispatches(events) {
115 +export function accumulateTwoPhaseDispatches(events) {
116 forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
117 }
118
111 -function accumulateTwoPhaseDispatchesSkipTarget(events) {
119 +export function accumulateTwoPhaseDispatchesSkipTarget(events) {
120 forEachAccumulated(events, accumulateTwoPhaseDispatchesSingleSkipTarget);
121 }
122
115 -function accumulateEnterLeaveDispatches(leave, enter, from, to) {
123 +export function accumulateEnterLeaveDispatches(leave, enter, from, to) {
124 traverseEnterLeave(from, to, accumulateDispatches, leave, enter);
125 }
126
119 -function accumulateDirectDispatches(events) {
127 +export function accumulateDirectDispatches(events) {
128 forEachAccumulated(events, accumulateDirectDispatchesSingle);
129 }
122 -
123 -/**
124 - * A small set of propagation patterns, each of which will accept a small amount
125 - * of information, and generate a set of "dispatch ready event objects" - which
126 - * are sets of events that have already been annotated with a set of dispatched
127 - * listener functions/ids. The API is designed this way to discourage these
128 - * propagation strategies from actually executing the dispatches, since we
129 - * always want to collect the entire set of dispatches before executing even a
130 - * single one.
131 - *
132 - * @constructor EventPropagators
133 - */
134 -var EventPropagators = {
135 - accumulateTwoPhaseDispatches: accumulateTwoPhaseDispatches,
136 - accumulateTwoPhaseDispatchesSkipTarget: accumulateTwoPhaseDispatchesSkipTarget,
137 - accumulateDirectDispatches: accumulateDirectDispatches,
138 - accumulateEnterLeaveDispatches: accumulateEnterLeaveDispatches,
139 -};
140 -
141 -export default EventPropagators;
packages/events/ReactControlledComponent.js
+30 -33
@@ -7,7 +7,10 @@
7
8 import invariant from 'fbjs/lib/invariant';
9
10 -import EventPluginUtils from './EventPluginUtils';
10 +import {
11 + getInstanceFromNode,
12 + getFiberCurrentPropsFromNode,
13 +} from './EventPluginUtils';
14
15 // Use to restore controlled state after a change event has fired.
16
@@ -27,7 +30,7 @@ var restoreQueue = null;
30 function restoreStateOfTarget(target) {
31 // We perform this translation at the end of the event loop so that we
32 // always receive the correct fiber here
30 - var internalInstance = EventPluginUtils.getInstanceFromNode(target);
33 + var internalInstance = getInstanceFromNode(target);
34 if (!internalInstance) {
35 // Unmounted
36 return;
@@ -38,9 +41,7 @@ function restoreStateOfTarget(target) {
41 'Fiber needs to be injected to handle a fiber target for controlled ' +
42 'events. This error is likely caused by a bug in React. Please file an issue.',
43 );
41 - const props = EventPluginUtils.getFiberCurrentPropsFromNode(
42 - internalInstance.stateNode,
43 - );
44 + const props = getFiberCurrentPropsFromNode(internalInstance.stateNode);
45 fiberHostComponent.restoreControlledState(
46 internalInstance.stateNode,
47 internalInstance.type,
@@ -48,37 +49,33 @@ function restoreStateOfTarget(target) {
49 );
50 }
51
51 -var ReactControlledComponent = {
52 - injection: ReactControlledComponentInjection,
52 +export const injection = ReactControlledComponentInjection;
53
54 - enqueueStateRestore(target) {
55 - if (restoreTarget) {
56 - if (restoreQueue) {
57 - restoreQueue.push(target);
58 - } else {
59 - restoreQueue = [target];
60 - }
54 +export function enqueueStateRestore(target) {
55 + if (restoreTarget) {
56 + if (restoreQueue) {
57 + restoreQueue.push(target);
58 } else {
62 - restoreTarget = target;
59 + restoreQueue = [target];
60 }
64 - },
61 + } else {
62 + restoreTarget = target;
63 + }
64 +}
65
66 - restoreStateIfNeeded() {
67 - if (!restoreTarget) {
68 - return;
69 - }
70 - var target = restoreTarget;
71 - var queuedTargets = restoreQueue;
72 - restoreTarget = null;
73 - restoreQueue = null;
66 +export function restoreStateIfNeeded() {
67 + if (!restoreTarget) {
68 + return;
69 + }
70 + var target = restoreTarget;
71 + var queuedTargets = restoreQueue;
72 + restoreTarget = null;
73 + restoreQueue = null;
74
75 - restoreStateOfTarget(target);
76 - if (queuedTargets) {
77 - for (var i = 0; i < queuedTargets.length; i++) {
78 - restoreStateOfTarget(queuedTargets[i]);
79 - }
75 + restoreStateOfTarget(target);
76 + if (queuedTargets) {
77 + for (var i = 0; i < queuedTargets.length; i++) {
78 + restoreStateOfTarget(queuedTargets[i]);
79 }
81 - },
82 -};
83 -
84 -export default ReactControlledComponent;
80 + }
81 +}
packages/events/ReactEventEmitterMixin.js
+21 -21
@@ -5,32 +5,32 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import EventPluginHub from './EventPluginHub';
8 +import {
9 + enqueueEvents,
10 + processEventQueue,
11 + extractEvents,
12 +} from './EventPluginHub';
13
14 function runEventQueueInBatch(events) {
11 - EventPluginHub.enqueueEvents(events);
12 - EventPluginHub.processEventQueue(false);
15 + enqueueEvents(events);
16 + processEventQueue(false);
17 }
18
15 -var ReactEventEmitterMixin = {
16 - /**
17 - * Streams a fired top-level event to `EventPluginHub` where plugins have the
18 - * opportunity to create `ReactEvent`s to be dispatched.
19 - */
20 - handleTopLevel: function(
19 +/**
20 + * Streams a fired top-level event to `EventPluginHub` where plugins have the
21 + * opportunity to create `ReactEvent`s to be dispatched.
22 + */
23 +export function handleTopLevel(
24 + topLevelType,
25 + targetInst,
26 + nativeEvent,
27 + nativeEventTarget,
28 +) {
29 + var events = extractEvents(
30 topLevelType,
31 targetInst,
32 nativeEvent,
33 nativeEventTarget,
25 - ) {
26 - var events = EventPluginHub.extractEvents(
27 - topLevelType,
28 - targetInst,
29 - nativeEvent,
30 - nativeEventTarget,
31 - );
32 - runEventQueueInBatch(events);
33 - },
34 -};
35 -
36 -export default ReactEventEmitterMixin;
34 + );
35 + runEventQueueInBatch(events);
36 +}
packages/events/ReactGenericBatching.js
+6 -17
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import ReactControlledComponent from './ReactControlledComponent';
8 +import {restoreStateIfNeeded} from './ReactControlledComponent';
9
10 // Used as a way to call batchedUpdates when we don't have a reference to
11 // the renderer. Such as when we're dispatching events or if third party
@@ -18,30 +18,24 @@ var fiberBatchedUpdates = function(fn, bookkeeping) {
18 return fn(bookkeeping);
19 };
20
21 -function batchedUpdates(fn, bookkeeping) {
22 - // If we have Fiber loaded, we need to wrap this in a batching call so that
23 - // Fiber can apply its default priority for this call.
24 - return fiberBatchedUpdates(fn, bookkeeping);
25 -}
26 -
21 var isNestingBatched = false;
28 -function batchedUpdatesWithControlledComponents(fn, bookkeeping) {
22 +export function batchedUpdates(fn, bookkeeping) {
23 if (isNestingBatched) {
24 // If we are currently inside another batch, we need to wait until it
25 // fully completes before restoring state. Therefore, we add the target to
26 // a queue of work.
33 - return batchedUpdates(fn, bookkeeping);
27 + return fiberBatchedUpdates(fn, bookkeeping);
28 }
29 isNestingBatched = true;
30 try {
37 - return batchedUpdates(fn, bookkeeping);
31 + return fiberBatchedUpdates(fn, bookkeeping);
32 } finally {
33 // Here we wait until all updates have propagated, which is important
34 // when using controlled components within layers:
35 // https://github.com/facebook/react/issues/1698
36 // Then we restore state of any controlled component.
37 isNestingBatched = false;
44 - ReactControlledComponent.restoreStateIfNeeded();
38 + restoreStateIfNeeded();
39 }
40 }
41
@@ -51,9 +45,4 @@ var ReactGenericBatchingInjection = {
45 },
46 };
47
54 -var ReactGenericBatching = {
55 - batchedUpdates: batchedUpdatesWithControlledComponents,
56 - injection: ReactGenericBatchingInjection,
57 -};
58 -
59 -export default ReactGenericBatching;
48 +export const injection = ReactGenericBatchingInjection;
packages/events/ResponderEventPlugin.js
+23 -19
@@ -7,20 +7,24 @@
7
8 import {getLowestCommonAncestor, isAncestor} from 'shared/ReactTreeTraversal';
9
10 -import EventPluginUtils from './EventPluginUtils';
11 -import EventPropagators from './EventPropagators';
10 +import {
11 + isStartish,
12 + isMoveish,
13 + isEndish,
14 + executeDirectDispatch,
15 + hasDispatches,
16 + executeDispatchesInOrderStopAtTrue,
17 + getInstanceFromNode,
18 +} from './EventPluginUtils';
19 +import {
20 + accumulateDirectDispatches,
21 + accumulateTwoPhaseDispatches,
22 + accumulateTwoPhaseDispatchesSkipTarget,
23 +} from './EventPropagators';
24 import ResponderSyntheticEvent from './ResponderSyntheticEvent';
25 import ResponderTouchHistoryStore from './ResponderTouchHistoryStore';
26 import accumulate from './accumulate';
27
16 -var isStartish = EventPluginUtils.isStartish;
17 -var isMoveish = EventPluginUtils.isMoveish;
18 -var isEndish = EventPluginUtils.isEndish;
19 -var executeDirectDispatch = EventPluginUtils.executeDirectDispatch;
20 -var hasDispatches = EventPluginUtils.hasDispatches;
21 -var executeDispatchesInOrderStopAtTrue =
22 - EventPluginUtils.executeDispatchesInOrderStopAtTrue;
23 -
28 /**
29 * Instance of element that should respond to touch/move types of interactions,
30 * as indicated explicitly by relevant callbacks.
@@ -340,9 +344,9 @@ function setResponderAndExtractTransfer(
344 );
345 shouldSetEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
346 if (skipOverBubbleShouldSetFrom) {
343 - EventPropagators.accumulateTwoPhaseDispatchesSkipTarget(shouldSetEvent);
347 + accumulateTwoPhaseDispatchesSkipTarget(shouldSetEvent);
348 } else {
345 - EventPropagators.accumulateTwoPhaseDispatches(shouldSetEvent);
349 + accumulateTwoPhaseDispatches(shouldSetEvent);
350 }
351 var wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);
352 if (!shouldSetEvent.isPersistent()) {
@@ -361,7 +365,7 @@ function setResponderAndExtractTransfer(
365 );
366 grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
367
364 - EventPropagators.accumulateDirectDispatches(grantEvent);
368 + accumulateDirectDispatches(grantEvent);
369 var blockHostResponder = executeDirectDispatch(grantEvent) === true;
370 if (responderInst) {
371 var terminationRequestEvent = ResponderSyntheticEvent.getPooled(
@@ -372,7 +376,7 @@ function setResponderAndExtractTransfer(
376 );
377 terminationRequestEvent.touchHistory =
378 ResponderTouchHistoryStore.touchHistory;
375 - EventPropagators.accumulateDirectDispatches(terminationRequestEvent);
379 + accumulateDirectDispatches(terminationRequestEvent);
380 var shouldSwitch =
381 !hasDispatches(terminationRequestEvent) ||
382 executeDirectDispatch(terminationRequestEvent);
@@ -388,7 +392,7 @@ function setResponderAndExtractTransfer(
392 nativeEventTarget,
393 );
394 terminateEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
391 - EventPropagators.accumulateDirectDispatches(terminateEvent);
395 + accumulateDirectDispatches(terminateEvent);
396 extracted = accumulate(extracted, [grantEvent, terminateEvent]);
397 changeResponder(wantsResponderInst, blockHostResponder);
398 } else {
@@ -399,7 +403,7 @@ function setResponderAndExtractTransfer(
403 nativeEventTarget,
404 );
405 rejectEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
402 - EventPropagators.accumulateDirectDispatches(rejectEvent);
406 + accumulateDirectDispatches(rejectEvent);
407 extracted = accumulate(extracted, rejectEvent);
408 }
409 } else {
@@ -447,7 +451,7 @@ function noResponderTouches(nativeEvent) {
451 var target = activeTouch.target;
452 if (target !== null && target !== undefined && target !== 0) {
453 // Is the original touch location inside of the current responder?
450 - var targetInst = EventPluginUtils.getInstanceFromNode(target);
454 + var targetInst = getInstanceFromNode(target);
455 if (isAncestor(responderInst, targetInst)) {
456 return false;
457 }
@@ -525,7 +529,7 @@ var ResponderEventPlugin = {
529 nativeEventTarget,
530 );
531 gesture.touchHistory = ResponderTouchHistoryStore.touchHistory;
528 - EventPropagators.accumulateDirectDispatches(gesture);
532 + accumulateDirectDispatches(gesture);
533 extracted = accumulate(extracted, gesture);
534 }
535
@@ -547,7 +551,7 @@ var ResponderEventPlugin = {
551 nativeEventTarget,
552 );
553 finalEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
550 - EventPropagators.accumulateDirectDispatches(finalEvent);
554 + accumulateDirectDispatches(finalEvent);
555 extracted = accumulate(extracted, finalEvent);
556 changeResponder(null);
557 }
packages/events/ResponderTouchHistoryStore.js
+1 -3
@@ -10,9 +10,7 @@
10 import invariant from 'fbjs/lib/invariant';
11 import warning from 'fbjs/lib/warning';
12
13 -import EventPluginUtils from './EventPluginUtils';
14 -
15 -const {isEndish, isMoveish, isStartish} = EventPluginUtils;
13 +import {isEndish, isMoveish, isStartish} from './EventPluginUtils';
14
15 /**
16 * Tracks the position and time of each active touch by `touch.identifier`. We
packages/events/__tests__/EventPluginRegistry-test.js
+1 -1
@@ -16,7 +16,7 @@ describe('EventPluginRegistry', () => {
16 beforeEach(() => {
17 jest.resetModuleRegistry();
18 // TODO: can we express this test with only public API?
19 - EventPluginRegistry = require('events/EventPluginRegistry').default;
19 + EventPluginRegistry = require('events/EventPluginRegistry');
20
21 createPlugin = function(properties) {
22 return Object.assign({extractEvents: function() {}}, properties);
packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.js
+4 -5
@@ -58,13 +58,12 @@ describe('ReactBrowserEventEmitter', () => {
58 LISTENER.mockClear();
59
60 // TODO: can we express this test with only public API?
61 - EventPluginHub = require('events/EventPluginHub').default;
62 - EventPluginRegistry = require('events/EventPluginRegistry').default;
61 + EventPluginHub = require('events/EventPluginHub');
62 + EventPluginRegistry = require('events/EventPluginRegistry');
63 React = require('react');
64 ReactDOM = require('react-dom');
65 - ReactDOMComponentTree = require('../client/ReactDOMComponentTree').default;
66 - ReactBrowserEventEmitter = require('../events/ReactBrowserEventEmitter')
67 - .default;
65 + ReactDOMComponentTree = require('../client/ReactDOMComponentTree');
66 + ReactBrowserEventEmitter = require('../events/ReactBrowserEventEmitter');
67 ReactTestUtils = require('react-dom/test-utils');
68 TapEventPlugin = require('../events/TapEventPlugin').default;
69
packages/react-dom/src/__tests__/ReactDOMComponentTree-test.js
+1 -1
@@ -34,7 +34,7 @@ describe('ReactDOMComponentTree', () => {
34 React = require('react');
35 ReactDOM = require('react-dom');
36 // TODO: can we express this test with only public API?
37 - ReactDOMComponentTree = require('../client/ReactDOMComponentTree').default;
37 + ReactDOMComponentTree = require('../client/ReactDOMComponentTree');
38 ReactDOMServer = require('react-dom/server');
39 });
40
packages/react-dom/src/__tests__/ReactServerRendering-test.js
+1 -1
@@ -35,7 +35,7 @@ describe('ReactDOMServer', () => {
35 ReactDOMServer = require('react-dom/server');
36
37 // TODO: can we express this test with only public API?
38 - var DOMProperty = require('../shared/DOMProperty').default;
38 + var DOMProperty = require('../shared/DOMProperty');
39 ROOT_ATTRIBUTE_NAME = DOMProperty.ROOT_ATTRIBUTE_NAME;
40 });
41
packages/react-dom/src/__tests__/ReactTreeTraversal-test.js
+1 -1
@@ -11,7 +11,7 @@
11
12 var React = require('react');
13 // TODO: can we express this test with only public API?
14 -var ReactDOMComponentTree = require('../client/ReactDOMComponentTree').default;
14 +var ReactDOMComponentTree = require('../client/ReactDOMComponentTree');
15 var ReactTestUtils = require('react-dom/test-utils');
16
17 /**
packages/react-dom/src/client/DOMPropertyOperations.js
+16 -13
@@ -5,17 +5,20 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import DOMProperty from '../shared/DOMProperty';
8 +import {
9 + ATTRIBUTE_NAME_CHAR,
10 + ATTRIBUTE_NAME_START_CHAR,
11 + ID_ATTRIBUTE_NAME,
12 + ROOT_ATTRIBUTE_NAME,
13 + getPropertyInfo,
14 + shouldSetAttribute,
15 +} from '../shared/DOMProperty';
16 import warning from 'fbjs/lib/warning';
17
18 // isAttributeNameSafe() is currently duplicated in DOMMarkupOperations.
19 // TODO: Find a better place for this.
20 var VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
14 - '^[' +
15 - DOMProperty.ATTRIBUTE_NAME_START_CHAR +
16 - '][' +
17 - DOMProperty.ATTRIBUTE_NAME_CHAR +
18 - ']*$',
21 + '^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$',
22 );
23 var illegalAttributeNameCache = {};
24 var validatedAttributeNameCache = {};
@@ -54,11 +57,11 @@ function shouldIgnoreValue(propertyInfo, value) {
57 */
58
59 export function setAttributeForID(node, id) {
57 - node.setAttribute(DOMProperty.ID_ATTRIBUTE_NAME, id);
60 + node.setAttribute(ID_ATTRIBUTE_NAME, id);
61 }
62
63 export function setAttributeForRoot(node) {
61 - node.setAttribute(DOMProperty.ROOT_ATTRIBUTE_NAME, '');
64 + node.setAttribute(ROOT_ATTRIBUTE_NAME, '');
65 }
66
67 /**
@@ -68,7 +71,7 @@ export function setAttributeForRoot(node) {
71 */
72 export function getValueForProperty(node, name, expected) {
73 if (__DEV__) {
71 - var propertyInfo = DOMProperty.getPropertyInfo(name);
74 + var propertyInfo = getPropertyInfo(name);
75 if (propertyInfo) {
76 var mutationMethod = propertyInfo.mutationMethod;
77 if (mutationMethod || propertyInfo.mustUseProperty) {
@@ -151,9 +154,9 @@ export function getValueForAttribute(node, name, expected) {
154 * @param {*} value
155 */
156 export function setValueForProperty(node, name, value) {
154 - var propertyInfo = DOMProperty.getPropertyInfo(name);
157 + var propertyInfo = getPropertyInfo(name);
158
156 - if (propertyInfo && DOMProperty.shouldSetAttribute(name, value)) {
159 + if (propertyInfo && shouldSetAttribute(name, value)) {
160 var mutationMethod = propertyInfo.mutationMethod;
161 if (mutationMethod) {
162 mutationMethod(node, value);
@@ -184,7 +187,7 @@ export function setValueForProperty(node, name, value) {
187 setValueForAttribute(
188 node,
189 name,
187 - DOMProperty.shouldSetAttribute(name, value) ? value : null,
190 + shouldSetAttribute(name, value) ? value : null,
191 );
192 return;
193 }
@@ -228,7 +231,7 @@ export function deleteValueForAttribute(node, name) {
231 * @param {string} name
232 */
233 export function deleteValueForProperty(node, name) {
231 - var propertyInfo = DOMProperty.getPropertyInfo(name);
234 + var propertyInfo = getPropertyInfo(name);
235 if (propertyInfo) {
236 var mutationMethod = propertyInfo.mutationMethod;
237 if (mutationMethod) {
packages/react-dom/src/client/ReactDOM.js
+9 -11
@@ -19,11 +19,11 @@ import * as ReactPortal from 'react-reconciler/src/ReactPortal';
19 // TODO: direct imports like some-package/src/* are bad. Fix me.
20 import {injectInternals} from 'react-reconciler/src/ReactFiberDevToolsHook';
21 import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
22 -import ReactGenericBatching from 'events/ReactGenericBatching';
23 -import ReactControlledComponent from 'events/ReactControlledComponent';
24 -import EventPluginHub from 'events/EventPluginHub';
25 -import EventPluginRegistry from 'events/EventPluginRegistry';
26 -import EventPropagators from 'events/EventPropagators';
22 +import * as ReactGenericBatching from 'events/ReactGenericBatching';
23 +import * as ReactControlledComponent from 'events/ReactControlledComponent';
24 +import * as EventPluginHub from 'events/EventPluginHub';
25 +import * as EventPluginRegistry from 'events/EventPluginRegistry';
26 +import * as EventPropagators from 'events/EventPropagators';
27 import * as ReactInstanceMap from 'shared/ReactInstanceMap';
28 import ReactFeatureFlags from 'shared/ReactFeatureFlags';
29 import ReactVersion from 'shared/ReactVersion';
@@ -34,12 +34,12 @@ import invariant from 'fbjs/lib/invariant';
34 import lowPriorityWarning from 'shared/lowPriorityWarning';
35 import warning from 'fbjs/lib/warning';
36
37 -import ReactDOMComponentTree from './ReactDOMComponentTree';
37 +import * as ReactDOMComponentTree from './ReactDOMComponentTree';
38 import * as ReactDOMFiberComponent from './ReactDOMFiberComponent';
39 import * as ReactInputSelection from './ReactInputSelection';
40 import validateDOMNesting from './validateDOMNesting';
41 -import ReactBrowserEventEmitter from '../events/ReactBrowserEventEmitter';
42 -import ReactDOMEventListener from '../events/ReactDOMEventListener';
41 +import * as ReactBrowserEventEmitter from '../events/ReactBrowserEventEmitter';
42 +import * as ReactDOMEventListener from '../events/ReactDOMEventListener';
43 import {getChildNamespace} from '../shared/DOMNamespaces';
44 import {
45 ELEMENT_NODE,
@@ -48,9 +48,7 @@ import {
48 DOCUMENT_NODE,
49 DOCUMENT_FRAGMENT_NODE,
50 } from '../shared/HTMLNodeType';
51 -import DOMProperty from '../shared/DOMProperty';
52 -
53 -var {ROOT_ATTRIBUTE_NAME} = DOMProperty;
51 +import {ROOT_ATTRIBUTE_NAME} from '../shared/DOMProperty';
52 var {
53 createElement,
54 createTextNode,
packages/react-dom/src/client/ReactDOMClientInjection.js
+6 -8
@@ -5,22 +5,20 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import EventPluginHub from 'events/EventPluginHub';
9 -import EventPluginUtils from 'events/EventPluginUtils';
8 +import * as EventPluginHub from 'events/EventPluginHub';
9 +import * as EventPluginUtils from 'events/EventPluginUtils';
10
11 -import ReactDOMComponentTree from './ReactDOMComponentTree';
11 +import * as ReactDOMComponentTree from './ReactDOMComponentTree';
12 import BeforeInputEventPlugin from '../events/BeforeInputEventPlugin';
13 import ChangeEventPlugin from '../events/ChangeEventPlugin';
14 import DOMEventPluginOrder from '../events/DOMEventPluginOrder';
15 import EnterLeaveEventPlugin from '../events/EnterLeaveEventPlugin';
16 -import ReactBrowserEventEmitter from '../events/ReactBrowserEventEmitter';
17 -import ReactDOMEventListener from '../events/ReactDOMEventListener';
16 +import {handleTopLevel} from '../events/ReactBrowserEventEmitter';
17 +import {setHandleTopLevel} from '../events/ReactDOMEventListener';
18 import SelectEventPlugin from '../events/SelectEventPlugin';
19 import SimpleEventPlugin from '../events/SimpleEventPlugin';
20
21 -ReactDOMEventListener.setHandleTopLevel(
22 - ReactBrowserEventEmitter.handleTopLevel,
23 -);
21 +setHandleTopLevel(handleTopLevel);
22
23 /**
24 * Inject modules for resolving DOM hierarchy and plugin ordering.
packages/react-dom/src/client/ReactDOMComponentTree.js
+6 -17
@@ -12,7 +12,7 @@ var randomKey = Math.random().toString(36).slice(2);
12 var internalInstanceKey = '__reactInternalInstance$' + randomKey;
13 var internalEventHandlersKey = '__reactEventHandlers$' + randomKey;
14
15 -function precacheFiberNode(hostInst, node) {
15 +export function precacheFiberNode(hostInst, node) {
16 node[internalInstanceKey] = hostInst;
17 }
18
@@ -20,7 +20,7 @@ function precacheFiberNode(hostInst, node) {
20 * Given a DOM node, return the closest ReactDOMComponent or
21 * ReactDOMTextComponent instance ancestor.
22 */
23 -function getClosestInstanceFromNode(node) {
23 +export function getClosestInstanceFromNode(node) {
24 if (node[internalInstanceKey]) {
25 return node[internalInstanceKey];
26 }
@@ -55,7 +55,7 @@ function getClosestInstanceFromNode(node) {
55 * Given a DOM node, return the ReactDOMComponent or ReactDOMTextComponent
56 * instance, or null if the node was not rendered by this React.
57 */
58 -function getInstanceFromNode(node) {
58 +export function getInstanceFromNode(node) {
59 var inst = node[internalInstanceKey];
60 if (inst) {
61 if (inst.tag === HostComponent || inst.tag === HostText) {
@@ -71,7 +71,7 @@ function getInstanceFromNode(node) {
71 * Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
72 * DOM node.
73 */
74 -function getNodeFromInstance(inst) {
74 +export function getNodeFromInstance(inst) {
75 if (inst.tag === HostComponent || inst.tag === HostText) {
76 // In Fiber this, is just the state node right now. We assume it will be
77 // a host component or host text.
@@ -83,21 +83,10 @@ function getNodeFromInstance(inst) {
83 invariant(false, 'getNodeFromInstance: Invalid argument.');
84 }
85
86 -function getFiberCurrentPropsFromNode(node) {
86 +export function getFiberCurrentPropsFromNode(node) {
87 return node[internalEventHandlersKey] || null;
88 }
89
90 -function updateFiberProps(node, props) {
90 +export function updateFiberProps(node, props) {
91 node[internalEventHandlersKey] = props;
92 }
93 -
94 -var ReactDOMComponentTree = {
95 - getClosestInstanceFromNode: getClosestInstanceFromNode,
96 - getInstanceFromNode: getInstanceFromNode,
97 - getNodeFromInstance: getNodeFromInstance,
98 - precacheFiberNode: precacheFiberNode,
99 - getFiberCurrentPropsFromNode,
100 - updateFiberProps,
101 -};
102 -
103 -export default ReactDOMComponentTree;
packages/react-dom/src/client/ReactDOMFB.js
+2 -2
@@ -15,8 +15,8 @@ import * as ReactFiberErrorLogger
15 import ReactErrorUtils from 'shared/ReactErrorUtils';
16
17 import ReactDOM from './ReactDOM';
18 -import ReactBrowserEventEmitter from '../events/ReactBrowserEventEmitter';
19 -import ReactDOMComponentTree from './ReactDOMComponentTree';
18 +import * as ReactBrowserEventEmitter from '../events/ReactBrowserEventEmitter';
19 +import * as ReactDOMComponentTree from './ReactDOMComponentTree';
20 import TapEventPlugin from '../events/TapEventPlugin';
21
22 Object.assign(
packages/react-dom/src/client/ReactDOMFiberComponent.js
+27 -102
@@ -10,7 +10,7 @@
10 // TODO: direct imports like some-package/src/* are bad. Fix me.
11 import ReactDebugCurrentFiber
12 from 'react-reconciler/src/ReactDebugCurrentFiber';
13 -import EventPluginRegistry from 'events/EventPluginRegistry';
13 +import {registrationNameModules} from 'events/EventPluginRegistry';
14 import emptyFunction from 'fbjs/lib/emptyFunction';
15 import warning from 'fbjs/lib/warning';
16
@@ -22,10 +22,10 @@ import * as ReactDOMFiberTextarea from './ReactDOMFiberTextarea';
22 import * as inputValueTracking from './inputValueTracking';
23 import setInnerHTML from './setInnerHTML';
24 import setTextContent from './setTextContent';
25 -import ReactBrowserEventEmitter from '../events/ReactBrowserEventEmitter';
25 +import {listenTo, trapBubbledEvent} from '../events/ReactBrowserEventEmitter';
26 import * as CSSPropertyOperations from '../shared/CSSPropertyOperations';
27 import {Namespaces, getIntrinsicNamespace} from '../shared/DOMNamespaces';
28 -import DOMProperty from '../shared/DOMProperty';
28 +import {getPropertyInfo, shouldSetAttribute} from '../shared/DOMProperty';
29 import assertValidProps from '../shared/assertValidProps';
30 import {DOCUMENT_NODE, DOCUMENT_FRAGMENT_NODE} from '../shared/HTMLNodeType';
31 import isCustomComponent from '../shared/isCustomComponent';
@@ -46,9 +46,6 @@ var {
46 var didWarnInvalidHydration = false;
47 var didWarnShadyDOM = false;
48
49 -var listenTo = ReactBrowserEventEmitter.listenTo;
50 -var registrationNameModules = EventPluginRegistry.registrationNameModules;
51 -
49 var DANGEROUSLY_SET_INNER_HTML = 'dangerouslySetInnerHTML';
50 var SUPPRESS_CONTENT_EDITABLE_WARNING = 'suppressContentEditableWarning';
51 var SUPPRESS_HYDRATION_WARNING = 'suppressHydrationWarning';
@@ -467,7 +464,7 @@ export function setInitialProperties(
464 switch (tag) {
465 case 'iframe':
466 case 'object':
470 - ReactBrowserEventEmitter.trapBubbledEvent('topLoad', 'load', domElement);
467 + trapBubbledEvent('topLoad', 'load', domElement);
468 props = rawProps;
469 break;
470 case 'video':
@@ -475,62 +472,34 @@ export function setInitialProperties(
472 // Create listener for each media event
473 for (var event in mediaEvents) {
474 if (mediaEvents.hasOwnProperty(event)) {
478 - ReactBrowserEventEmitter.trapBubbledEvent(
479 - event,
480 - mediaEvents[event],
481 - domElement,
482 - );
475 + trapBubbledEvent(event, mediaEvents[event], domElement);
476 }
477 }
478 props = rawProps;
479 break;
480 case 'source':
488 - ReactBrowserEventEmitter.trapBubbledEvent(
489 - 'topError',
490 - 'error',
491 - domElement,
492 - );
481 + trapBubbledEvent('topError', 'error', domElement);
482 props = rawProps;
483 break;
484 case 'img':
485 case 'image':
497 - ReactBrowserEventEmitter.trapBubbledEvent(
498 - 'topError',
499 - 'error',
500 - domElement,
501 - );
502 - ReactBrowserEventEmitter.trapBubbledEvent('topLoad', 'load', domElement);
486 + trapBubbledEvent('topError', 'error', domElement);
487 + trapBubbledEvent('topLoad', 'load', domElement);
488 props = rawProps;
489 break;
490 case 'form':
506 - ReactBrowserEventEmitter.trapBubbledEvent(
507 - 'topReset',
508 - 'reset',
509 - domElement,
510 - );
511 - ReactBrowserEventEmitter.trapBubbledEvent(
512 - 'topSubmit',
513 - 'submit',
514 - domElement,
515 - );
491 + trapBubbledEvent('topReset', 'reset', domElement);
492 + trapBubbledEvent('topSubmit', 'submit', domElement);
493 props = rawProps;
494 break;
495 case 'details':
519 - ReactBrowserEventEmitter.trapBubbledEvent(
520 - 'topToggle',
521 - 'toggle',
522 - domElement,
523 - );
496 + trapBubbledEvent('topToggle', 'toggle', domElement);
497 props = rawProps;
498 break;
499 case 'input':
500 ReactDOMFiberInput.initWrapperState(domElement, rawProps);
501 props = ReactDOMFiberInput.getHostProps(domElement, rawProps);
529 - ReactBrowserEventEmitter.trapBubbledEvent(
530 - 'topInvalid',
531 - 'invalid',
532 - domElement,
533 - );
502 + trapBubbledEvent('topInvalid', 'invalid', domElement);
503 // For controlled components we always need to ensure we're listening
504 // to onChange. Even if there is no listener.
505 ensureListeningTo(rootContainerElement, 'onChange');
@@ -542,11 +511,7 @@ export function setInitialProperties(
511 case 'select':
512 ReactDOMFiberSelect.initWrapperState(domElement, rawProps);
513 props = ReactDOMFiberSelect.getHostProps(domElement, rawProps);
545 - ReactBrowserEventEmitter.trapBubbledEvent(
546 - 'topInvalid',
547 - 'invalid',
548 - domElement,
549 - );
514 + trapBubbledEvent('topInvalid', 'invalid', domElement);
515 // For controlled components we always need to ensure we're listening
516 // to onChange. Even if there is no listener.
517 ensureListeningTo(rootContainerElement, 'onChange');
@@ -554,11 +519,7 @@ export function setInitialProperties(
519 case 'textarea':
520 ReactDOMFiberTextarea.initWrapperState(domElement, rawProps);
521 props = ReactDOMFiberTextarea.getHostProps(domElement, rawProps);
557 - ReactBrowserEventEmitter.trapBubbledEvent(
558 - 'topInvalid',
559 - 'invalid',
560 - domElement,
561 - );
522 + trapBubbledEvent('topInvalid', 'invalid', domElement);
523 // For controlled components we always need to ensure we're listening
524 // to onChange. Even if there is no listener.
525 ensureListeningTo(rootContainerElement, 'onChange');
@@ -871,63 +832,35 @@ export function diffHydratedProperties(
832 switch (tag) {
833 case 'iframe':
834 case 'object':
874 - ReactBrowserEventEmitter.trapBubbledEvent('topLoad', 'load', domElement);
835 + trapBubbledEvent('topLoad', 'load', domElement);
836 break;
837 case 'video':
838 case 'audio':
839 // Create listener for each media event
840 for (var event in mediaEvents) {
841 if (mediaEvents.hasOwnProperty(event)) {
881 - ReactBrowserEventEmitter.trapBubbledEvent(
882 - event,
883 - mediaEvents[event],
884 - domElement,
885 - );
842 + trapBubbledEvent(event, mediaEvents[event], domElement);
843 }
844 }
845 break;
846 case 'source':
890 - ReactBrowserEventEmitter.trapBubbledEvent(
891 - 'topError',
892 - 'error',
893 - domElement,
894 - );
847 + trapBubbledEvent('topError', 'error', domElement);
848 break;
849 case 'img':
850 case 'image':
898 - ReactBrowserEventEmitter.trapBubbledEvent(
899 - 'topError',
900 - 'error',
901 - domElement,
902 - );
903 - ReactBrowserEventEmitter.trapBubbledEvent('topLoad', 'load', domElement);
851 + trapBubbledEvent('topError', 'error', domElement);
852 + trapBubbledEvent('topLoad', 'load', domElement);
853 break;
854 case 'form':
906 - ReactBrowserEventEmitter.trapBubbledEvent(
907 - 'topReset',
908 - 'reset',
909 - domElement,
910 - );
911 - ReactBrowserEventEmitter.trapBubbledEvent(
912 - 'topSubmit',
913 - 'submit',
914 - domElement,
915 - );
855 + trapBubbledEvent('topReset', 'reset', domElement);
856 + trapBubbledEvent('topSubmit', 'submit', domElement);
857 break;
858 case 'details':
918 - ReactBrowserEventEmitter.trapBubbledEvent(
919 - 'topToggle',
920 - 'toggle',
921 - domElement,
922 - );
859 + trapBubbledEvent('topToggle', 'toggle', domElement);
860 break;
861 case 'input':
862 ReactDOMFiberInput.initWrapperState(domElement, rawProps);
926 - ReactBrowserEventEmitter.trapBubbledEvent(
927 - 'topInvalid',
928 - 'invalid',
929 - domElement,
930 - );
863 + trapBubbledEvent('topInvalid', 'invalid', domElement);
864 // For controlled components we always need to ensure we're listening
865 // to onChange. Even if there is no listener.
866 ensureListeningTo(rootContainerElement, 'onChange');
@@ -937,22 +870,14 @@ export function diffHydratedProperties(
870 break;
871 case 'select':
872 ReactDOMFiberSelect.initWrapperState(domElement, rawProps);
940 - ReactBrowserEventEmitter.trapBubbledEvent(
941 - 'topInvalid',
942 - 'invalid',
943 - domElement,
944 - );
873 + trapBubbledEvent('topInvalid', 'invalid', domElement);
874 // For controlled components we always need to ensure we're listening
875 // to onChange. Even if there is no listener.
876 ensureListeningTo(rootContainerElement, 'onChange');
877 break;
878 case 'textarea':
879 ReactDOMFiberTextarea.initWrapperState(domElement, rawProps);
951 - ReactBrowserEventEmitter.trapBubbledEvent(
952 - 'topInvalid',
953 - 'invalid',
954 - domElement,
955 - );
880 + trapBubbledEvent('topInvalid', 'invalid', domElement);
881 // For controlled components we always need to ensure we're listening
882 // to onChange. Even if there is no listener.
883 ensureListeningTo(rootContainerElement, 'onChange');
@@ -1069,8 +994,8 @@ export function diffHydratedProperties(
994 if (nextProp !== serverValue) {
995 warnForPropDifference(propKey, serverValue, nextProp);
996 }
1072 - } else if (DOMProperty.shouldSetAttribute(propKey, nextProp)) {
1073 - if ((propertyInfo = DOMProperty.getPropertyInfo(propKey))) {
997 + } else if (shouldSetAttribute(propKey, nextProp)) {
998 + if ((propertyInfo = getPropertyInfo(propKey))) {
999 // $FlowFixMe - Should be inferred as not undefined.
1000 extraAttributeNames.delete(propertyInfo.attributeName);
1001 serverValue = DOMPropertyOperations.getValueForProperty(
packages/react-dom/src/client/ReactDOMFiberInput.js
+2 -4
@@ -14,7 +14,7 @@ import invariant from 'fbjs/lib/invariant';
14 import warning from 'fbjs/lib/warning';
15
16 import * as DOMPropertyOperations from './DOMPropertyOperations';
17 -import ReactDOMComponentTree from './ReactDOMComponentTree';
17 +import {getFiberCurrentPropsFromNode} from './ReactDOMComponentTree';
18 import ReactControlledValuePropTypes
19 from '../shared/ReactControlledValuePropTypes';
20
@@ -317,9 +317,7 @@ function updateNamedCousins(rootNode, props) {
317 // and the same name are rendered into the same form (same as #1939).
318 // That's probably okay; we don't support it just as we don't support
319 // mixing React radio buttons with non-React ones.
320 - var otherProps = ReactDOMComponentTree.getFiberCurrentPropsFromNode(
321 - otherNode,
322 - );
320 + var otherProps = getFiberCurrentPropsFromNode(otherNode);
321 invariant(
322 otherProps,
323 'ReactDOMInput: Mixing React and non-React radio inputs with the ' +
packages/react-dom/src/events/BeforeInputEventPlugin.js
+4 -4
@@ -7,10 +7,10 @@
7
8 import type {TopLevelTypes} from './BrowserEventConstants';
9
10 -import EventPropagators from 'events/EventPropagators';
10 +import {accumulateTwoPhaseDispatches} from 'events/EventPropagators';
11 import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
12
13 -import FallbackCompositionState from './FallbackCompositionState';
13 +import * as FallbackCompositionState from './FallbackCompositionState';
14 import SyntheticCompositionEvent from './SyntheticCompositionEvent';
15 import SyntheticInputEvent from './SyntheticInputEvent';
16
@@ -263,7 +263,7 @@ function extractCompositionEvent(
263 }
264 }
265
266 - EventPropagators.accumulateTwoPhaseDispatches(event);
266 + accumulateTwoPhaseDispatches(event);
267 return event;
268 }
269
@@ -422,7 +422,7 @@ function extractBeforeInputEvent(
422 );
423
424 event.data = chars;
425 - EventPropagators.accumulateTwoPhaseDispatches(event);
425 + accumulateTwoPhaseDispatches(event);
426 return event;
427 }
428
packages/react-dom/src/events/ChangeEventPlugin.js
+12 -14
@@ -5,17 +5,17 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import EventPluginHub from 'events/EventPluginHub';
9 -import EventPropagators from 'events/EventPropagators';
10 -import ReactControlledComponent from 'events/ReactControlledComponent';
11 -import ReactGenericBatching from 'events/ReactGenericBatching';
8 +import {enqueueEvents, processEventQueue} from 'events/EventPluginHub';
9 +import {accumulateTwoPhaseDispatches} from 'events/EventPropagators';
10 +import {enqueueStateRestore} from 'events/ReactControlledComponent';
11 +import {batchedUpdates} from 'events/ReactGenericBatching';
12 import SyntheticEvent from 'events/SyntheticEvent';
13 import isTextInputElement from 'shared/isTextInputElement';
14 import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
15
16 import getEventTarget from './getEventTarget';
17 import isEventSupported from './isEventSupported';
18 -import ReactDOMComponentTree from '../client/ReactDOMComponentTree';
18 +import {getNodeFromInstance} from '../client/ReactDOMComponentTree';
19 import * as inputValueTracking from '../client/inputValueTracking';
20
21 var eventTypes = {
@@ -46,8 +46,8 @@ function createAndAccumulateChangeEvent(inst, nativeEvent, target) {
46 );
47 event.type = 'change';
48 // Flag this event loop as needing state restore.
49 - ReactControlledComponent.enqueueStateRestore(target);
50 - EventPropagators.accumulateTwoPhaseDispatches(event);
49 + enqueueStateRestore(target);
50 + accumulateTwoPhaseDispatches(event);
51 return event;
52 }
53 /**
@@ -84,16 +84,16 @@ function manualDispatchChangeEvent(nativeEvent) {
84 // components don't work properly in conjunction with event bubbling because
85 // the component is rerendered and the value reverted before all the event
86 // handlers can run. See https://github.com/facebook/react/issues/708.
87 - ReactGenericBatching.batchedUpdates(runEventInBatch, event);
87 + batchedUpdates(runEventInBatch, event);
88 }
89
90 function runEventInBatch(event) {
91 - EventPluginHub.enqueueEvents(event);
92 - EventPluginHub.processEventQueue(false);
91 + enqueueEvents(event);
92 + processEventQueue(false);
93 }
94
95 function getInstIfValueChanged(targetInst) {
96 - const targetNode = ReactDOMComponentTree.getNodeFromInstance(targetInst);
96 + const targetNode = getNodeFromInstance(targetInst);
97 if (inputValueTracking.updateValueIfChanged(targetNode)) {
98 return targetInst;
99 }
@@ -262,9 +262,7 @@ var ChangeEventPlugin = {
262 nativeEvent,
263 nativeEventTarget,
264 ) {
265 - var targetNode = targetInst
266 - ? ReactDOMComponentTree.getNodeFromInstance(targetInst)
267 - : window;
265 + var targetNode = targetInst ? getNodeFromInstance(targetInst) : window;
266
267 var getTargetInstFunc, handleEventFunc;
268 if (shouldUseChangeEvent(targetNode)) {
packages/react-dom/src/events/EnterLeaveEventPlugin.js
+9 -12
@@ -5,10 +5,13 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import EventPropagators from 'events/EventPropagators';
8 +import {accumulateEnterLeaveDispatches} from 'events/EventPropagators';
9
10 import SyntheticMouseEvent from './SyntheticMouseEvent';
11 -import ReactDOMComponentTree from '../client/ReactDOMComponentTree';
11 +import {
12 + getClosestInstanceFromNode,
13 + getNodeFromInstance,
14 +} from '../client/ReactDOMComponentTree';
15
16 var eventTypes = {
17 mouseEnter: {
@@ -67,9 +70,7 @@ var EnterLeaveEventPlugin = {
70 if (topLevelType === 'topMouseOut') {
71 from = targetInst;
72 var related = nativeEvent.relatedTarget || nativeEvent.toElement;
70 - to = related
71 - ? ReactDOMComponentTree.getClosestInstanceFromNode(related)
72 - : null;
73 + to = related ? getClosestInstanceFromNode(related) : null;
74 } else {
75 // Moving to a node from outside the window.
76 from = null;
@@ -81,12 +82,8 @@ var EnterLeaveEventPlugin = {
82 return null;
83 }
84
84 - var fromNode = from == null
85 - ? win
86 - : ReactDOMComponentTree.getNodeFromInstance(from);
87 - var toNode = to == null
88 - ? win
89 - : ReactDOMComponentTree.getNodeFromInstance(to);
85 + var fromNode = from == null ? win : getNodeFromInstance(from);
86 + var toNode = to == null ? win : getNodeFromInstance(to);
87
88 var leave = SyntheticMouseEvent.getPooled(
89 eventTypes.mouseLeave,
@@ -108,7 +105,7 @@ var EnterLeaveEventPlugin = {
105 enter.target = toNode;
106 enter.relatedTarget = fromNode;
107
111 - EventPropagators.accumulateEnterLeaveDispatches(leave, enter, from, to);
108 + accumulateEnterLeaveDispatches(leave, enter, from, to);
109
110 return [leave, enter];
111 },
packages/react-dom/src/events/FallbackCompositionState.js
+41 -42
@@ -24,52 +24,51 @@ var compositionState = {
24 _fallbackText: null,
25 };
26
27 -var FallbackCompositionState = {
28 - initialize(nativeEventTarget) {
29 - compositionState._root = nativeEventTarget;
30 - compositionState._startText = FallbackCompositionState.getText();
31 - return true;
32 - },
33 - reset() {
34 - compositionState._root = null;
35 - compositionState._startText = null;
36 - compositionState._fallbackText = null;
37 - },
38 - getData() {
39 - if (compositionState._fallbackText) {
40 - return compositionState._fallbackText;
41 - }
27 +export function initialize(nativeEventTarget) {
28 + compositionState._root = nativeEventTarget;
29 + compositionState._startText = getText();
30 + return true;
31 +}
32
43 - var start;
44 - var startValue = compositionState._startText;
45 - var startLength = startValue.length;
46 - var end;
47 - var endValue = FallbackCompositionState.getText();
48 - var endLength = endValue.length;
33 +export function reset() {
34 + compositionState._root = null;
35 + compositionState._startText = null;
36 + compositionState._fallbackText = null;
37 +}
38
50 - for (start = 0; start < startLength; start++) {
51 - if (startValue[start] !== endValue[start]) {
52 - break;
53 - }
54 - }
39 +export function getData() {
40 + if (compositionState._fallbackText) {
41 + return compositionState._fallbackText;
42 + }
43 +
44 + var start;
45 + var startValue = compositionState._startText;
46 + var startLength = startValue.length;
47 + var end;
48 + var endValue = getText();
49 + var endLength = endValue.length;
50
56 - var minEnd = startLength - start;
57 - for (end = 1; end <= minEnd; end++) {
58 - if (startValue[startLength - end] !== endValue[endLength - end]) {
59 - break;
60 - }
51 + for (start = 0; start < startLength; start++) {
52 + if (startValue[start] !== endValue[start]) {
53 + break;
54 }
55 + }
56
63 - var sliceTail = end > 1 ? 1 - end : undefined;
64 - compositionState._fallbackText = endValue.slice(start, sliceTail);
65 - return compositionState._fallbackText;
66 - },
67 - getText() {
68 - if ('value' in compositionState._root) {
69 - return compositionState._root.value;
57 + var minEnd = startLength - start;
58 + for (end = 1; end <= minEnd; end++) {
59 + if (startValue[startLength - end] !== endValue[endLength - end]) {
60 + break;
61 }
71 - return compositionState._root[getTextContentAccessor()];
72 - },
73 -};
62 + }
63 +
64 + var sliceTail = end > 1 ? 1 - end : undefined;
65 + compositionState._fallbackText = endValue.slice(start, sliceTail);
66 + return compositionState._fallbackText;
67 +}
68
75 -export default FallbackCompositionState;
69 +export function getText() {
70 + if ('value' in compositionState._root) {
71 + return compositionState._root.value;
72 + }
73 + return compositionState._root[getTextContentAccessor()];
74 +}
packages/react-dom/src/events/ReactBrowserEventEmitter.js
+84 -148
@@ -5,13 +5,19 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import EventPluginRegistry from 'events/EventPluginRegistry';
9 -import ReactEventEmitterMixin from 'events/ReactEventEmitterMixin';
10 -
11 -import ReactDOMEventListener from './ReactDOMEventListener';
8 +import {registrationNameDependencies} from 'events/EventPluginRegistry';
9 +
10 +import {
11 + setEnabled,
12 + isEnabled,
13 + trapBubbledEvent,
14 + trapCapturedEvent,
15 +} from './ReactDOMEventListener';
16 import isEventSupported from './isEventSupported';
17 import BrowserEventConstants from './BrowserEventConstants';
18
19 +export * from 'events/ReactEventEmitterMixin';
20 +
21 var {topLevelTypes} = BrowserEventConstants;
22
23 /**
@@ -88,153 +94,83 @@ function getListeningForDocument(mountAt) {
94 return alreadyListeningTo[mountAt[topListenersIDKey]];
95 }
96
91 -var ReactBrowserEventEmitter = Object.assign({}, ReactEventEmitterMixin, {
92 - /**
93 - * Sets whether or not any created callbacks should be enabled.
94 - *
95 - * @param {boolean} enabled True if callbacks should be enabled.
96 - */
97 - setEnabled: function(enabled) {
98 - if (ReactDOMEventListener) {
99 - ReactDOMEventListener.setEnabled(enabled);
100 - }
101 - },
102 -
103 - /**
104 - * @return {boolean} True if callbacks are enabled.
105 - */
106 - isEnabled: function() {
107 - return !!(ReactDOMEventListener && ReactDOMEventListener.isEnabled());
108 - },
109 -
110 - /**
111 - * We listen for bubbled touch events on the document object.
112 - *
113 - * Firefox v8.01 (and possibly others) exhibited strange behavior when
114 - * mounting `onmousemove` events at some node that was not the document
115 - * element. The symptoms were that if your mouse is not moving over something
116 - * contained within that mount point (for example on the background) the
117 - * top-level listeners for `onmousemove` won't be called. However, if you
118 - * register the `mousemove` on the document object, then it will of course
119 - * catch all `mousemove`s. This along with iOS quirks, justifies restricting
120 - * top-level listeners to the document object only, at least for these
121 - * movement types of events and possibly all events.
122 - *
123 - * @see http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
124 - *
125 - * Also, `keyup`/`keypress`/`keydown` do not bubble to the window on IE, but
126 - * they bubble to document.
127 - *
128 - * @param {string} registrationName Name of listener (e.g. `onClick`).
129 - * @param {object} contentDocumentHandle Document which owns the container
130 - */
131 - listenTo: function(registrationName, contentDocumentHandle) {
132 - var mountAt = contentDocumentHandle;
133 - var isListening = getListeningForDocument(mountAt);
134 - var dependencies =
135 - EventPluginRegistry.registrationNameDependencies[registrationName];
136 -
137 - for (var i = 0; i < dependencies.length; i++) {
138 - var dependency = dependencies[i];
139 - if (
140 - !(isListening.hasOwnProperty(dependency) && isListening[dependency])
141 - ) {
142 - if (dependency === 'topWheel') {
143 - if (isEventSupported('wheel')) {
144 - ReactDOMEventListener.trapBubbledEvent(
145 - 'topWheel',
146 - 'wheel',
147 - mountAt,
148 - );
149 - } else if (isEventSupported('mousewheel')) {
150 - ReactDOMEventListener.trapBubbledEvent(
151 - 'topWheel',
152 - 'mousewheel',
153 - mountAt,
154 - );
155 - } else {
156 - // Firefox needs to capture a different mouse scroll event.
157 - // @see http://www.quirksmode.org/dom/events/tests/scroll.html
158 - ReactDOMEventListener.trapBubbledEvent(
159 - 'topWheel',
160 - 'DOMMouseScroll',
161 - mountAt,
162 - );
163 - }
164 - } else if (dependency === 'topScroll') {
165 - ReactDOMEventListener.trapCapturedEvent(
166 - 'topScroll',
167 - 'scroll',
168 - mountAt,
169 - );
170 - } else if (dependency === 'topFocus' || dependency === 'topBlur') {
171 - ReactDOMEventListener.trapCapturedEvent('topFocus', 'focus', mountAt);
172 - ReactDOMEventListener.trapCapturedEvent('topBlur', 'blur', mountAt);
173 -
174 - // to make sure blur and focus event listeners are only attached once
175 - isListening.topBlur = true;
176 - isListening.topFocus = true;
177 - } else if (dependency === 'topCancel') {
178 - if (isEventSupported('cancel', true)) {
179 - ReactDOMEventListener.trapCapturedEvent(
180 - 'topCancel',
181 - 'cancel',
182 - mountAt,
183 - );
184 - }
185 - isListening.topCancel = true;
186 - } else if (dependency === 'topClose') {
187 - if (isEventSupported('close', true)) {
188 - ReactDOMEventListener.trapCapturedEvent(
189 - 'topClose',
190 - 'close',
191 - mountAt,
192 - );
193 - }
194 - isListening.topClose = true;
195 - } else if (topLevelTypes.hasOwnProperty(dependency)) {
196 - ReactDOMEventListener.trapBubbledEvent(
197 - dependency,
198 - topLevelTypes[dependency],
199 - mountAt,
200 - );
97 +/**
98 + * We listen for bubbled touch events on the document object.
99 + *
100 + * Firefox v8.01 (and possibly others) exhibited strange behavior when
101 + * mounting `onmousemove` events at some node that was not the document
102 + * element. The symptoms were that if your mouse is not moving over something
103 + * contained within that mount point (for example on the background) the
104 + * top-level listeners for `onmousemove` won't be called. However, if you
105 + * register the `mousemove` on the document object, then it will of course
106 + * catch all `mousemove`s. This along with iOS quirks, justifies restricting
107 + * top-level listeners to the document object only, at least for these
108 + * movement types of events and possibly all events.
109 + *
110 + * @see http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
111 + *
112 + * Also, `keyup`/`keypress`/`keydown` do not bubble to the window on IE, but
113 + * they bubble to document.
114 + *
115 + * @param {string} registrationName Name of listener (e.g. `onClick`).
116 + * @param {object} contentDocumentHandle Document which owns the container
117 + */
118 +export function listenTo(registrationName, contentDocumentHandle) {
119 + var mountAt = contentDocumentHandle;
120 + var isListening = getListeningForDocument(mountAt);
121 + var dependencies = registrationNameDependencies[registrationName];
122 +
123 + for (var i = 0; i < dependencies.length; i++) {
124 + var dependency = dependencies[i];
125 + if (!(isListening.hasOwnProperty(dependency) && isListening[dependency])) {
126 + if (dependency === 'topWheel') {
127 + if (isEventSupported('wheel')) {
128 + trapBubbledEvent('topWheel', 'wheel', mountAt);
129 + } else if (isEventSupported('mousewheel')) {
130 + trapBubbledEvent('topWheel', 'mousewheel', mountAt);
131 + } else {
132 + // Firefox needs to capture a different mouse scroll event.
133 + // @see http://www.quirksmode.org/dom/events/tests/scroll.html
134 + trapBubbledEvent('topWheel', 'DOMMouseScroll', mountAt);
135 }
202 -
203 - isListening[dependency] = true;
136 + } else if (dependency === 'topScroll') {
137 + trapCapturedEvent('topScroll', 'scroll', mountAt);
138 + } else if (dependency === 'topFocus' || dependency === 'topBlur') {
139 + trapCapturedEvent('topFocus', 'focus', mountAt);
140 + trapCapturedEvent('topBlur', 'blur', mountAt);
141 +
142 + // to make sure blur and focus event listeners are only attached once
143 + isListening.topBlur = true;
144 + isListening.topFocus = true;
145 + } else if (dependency === 'topCancel') {
146 + if (isEventSupported('cancel', true)) {
147 + trapCapturedEvent('topCancel', 'cancel', mountAt);
148 + }
149 + isListening.topCancel = true;
150 + } else if (dependency === 'topClose') {
151 + if (isEventSupported('close', true)) {
152 + trapCapturedEvent('topClose', 'close', mountAt);
153 + }
154 + isListening.topClose = true;
155 + } else if (topLevelTypes.hasOwnProperty(dependency)) {
156 + trapBubbledEvent(dependency, topLevelTypes[dependency], mountAt);
157 }
205 - }
206 - },
158
208 - isListeningToAllDependencies: function(registrationName, mountAt) {
209 - var isListening = getListeningForDocument(mountAt);
210 - var dependencies =
211 - EventPluginRegistry.registrationNameDependencies[registrationName];
212 - for (var i = 0; i < dependencies.length; i++) {
213 - var dependency = dependencies[i];
214 - if (
215 - !(isListening.hasOwnProperty(dependency) && isListening[dependency])
216 - ) {
217 - return false;
218 - }
159 + isListening[dependency] = true;
160 }
220 - return true;
221 - },
222 -
223 - trapBubbledEvent: function(topLevelType, handlerBaseName, handle) {
224 - return ReactDOMEventListener.trapBubbledEvent(
225 - topLevelType,
226 - handlerBaseName,
227 - handle,
228 - );
229 - },
161 + }
162 +}
163
231 - trapCapturedEvent: function(topLevelType, handlerBaseName, handle) {
232 - return ReactDOMEventListener.trapCapturedEvent(
233 - topLevelType,
234 - handlerBaseName,
235 - handle,
236 - );
237 - },
238 -});
164 +export function isListeningToAllDependencies(registrationName, mountAt) {
165 + var isListening = getListeningForDocument(mountAt);
166 + var dependencies = registrationNameDependencies[registrationName];
167 + for (var i = 0; i < dependencies.length; i++) {
168 + var dependency = dependencies[i];
169 + if (!(isListening.hasOwnProperty(dependency) && isListening[dependency])) {
170 + return false;
171 + }
172 + }
173 + return true;
174 +}
175
240 -export default ReactBrowserEventEmitter;
176 +export {setEnabled, isEnabled, trapBubbledEvent, trapCapturedEvent};
packages/react-dom/src/events/ReactDOMEventListener.js
+90 -95
@@ -5,13 +5,13 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import ReactGenericBatching from 'events/ReactGenericBatching';
8 +import {batchedUpdates} from 'events/ReactGenericBatching';
9 import {isFiberMounted} from 'shared/ReactFiberTreeReflection';
10 import {HostRoot} from 'shared/ReactTypeOfWork';
11 import EventListener from 'fbjs/lib/EventListener';
12
13 import getEventTarget from './getEventTarget';
14 -import ReactDOMComponentTree from '../client/ReactDOMComponentTree';
14 +import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
15
16 var CALLBACK_BOOKKEEPING_POOL_SIZE = 10;
17 var callbackBookkeepingPool = [];
@@ -80,12 +80,12 @@ function handleTopLevelImpl(bookKeeping) {
80 break;
81 }
82 bookKeeping.ancestors.push(ancestor);
83 - ancestor = ReactDOMComponentTree.getClosestInstanceFromNode(root);
83 + ancestor = getClosestInstanceFromNode(root);
84 } while (ancestor);
85
86 for (var i = 0; i < bookKeeping.ancestors.length; i++) {
87 targetInst = bookKeeping.ancestors[i];
88 - ReactDOMEventListener._handleTopLevel(
88 + _handleTopLevel(
89 bookKeeping.topLevelType,
90 targetInst,
91 bookKeeping.nativeEvent,
@@ -94,99 +94,94 @@ function handleTopLevelImpl(bookKeeping) {
94 }
95 }
96
97 -var ReactDOMEventListener = {
98 - _enabled: true,
99 - _handleTopLevel: null,
100 -
101 - setHandleTopLevel: function(handleTopLevel) {
102 - ReactDOMEventListener._handleTopLevel = handleTopLevel;
103 - },
104 -
105 - setEnabled: function(enabled) {
106 - ReactDOMEventListener._enabled = !!enabled;
107 - },
108 -
109 - isEnabled: function() {
110 - return ReactDOMEventListener._enabled;
111 - },
112 -
113 - /**
114 - * Traps top-level events by using event bubbling.
115 - *
116 - * @param {string} topLevelType Record from `BrowserEventConstants`.
117 - * @param {string} handlerBaseName Event name (e.g. "click").
118 - * @param {object} element Element on which to attach listener.
119 - * @return {?object} An object with a remove function which will forcefully
120 - * remove the listener.
121 - * @internal
122 - */
123 - trapBubbledEvent: function(topLevelType, handlerBaseName, element) {
124 - if (!element) {
125 - return null;
126 - }
127 - return EventListener.listen(
128 - element,
129 - handlerBaseName,
130 - ReactDOMEventListener.dispatchEvent.bind(null, topLevelType),
131 - );
132 - },
133 -
134 - /**
135 - * Traps a top-level event by using event capturing.
136 - *
137 - * @param {string} topLevelType Record from `BrowserEventConstants`.
138 - * @param {string} handlerBaseName Event name (e.g. "click").
139 - * @param {object} element Element on which to attach listener.
140 - * @return {?object} An object with a remove function which will forcefully
141 - * remove the listener.
142 - * @internal
143 - */
144 - trapCapturedEvent: function(topLevelType, handlerBaseName, element) {
145 - if (!element) {
146 - return null;
147 - }
148 - return EventListener.capture(
149 - element,
150 - handlerBaseName,
151 - ReactDOMEventListener.dispatchEvent.bind(null, topLevelType),
152 - );
153 - },
97 +// TODO: can we stop exporting these?
98 +export let _enabled = true;
99 +export let _handleTopLevel: null;
100
155 - dispatchEvent: function(topLevelType, nativeEvent) {
156 - if (!ReactDOMEventListener._enabled) {
157 - return;
158 - }
101 +export function setHandleTopLevel(handleTopLevel) {
102 + _handleTopLevel = handleTopLevel;
103 +}
104
160 - var nativeEventTarget = getEventTarget(nativeEvent);
161 - var targetInst = ReactDOMComponentTree.getClosestInstanceFromNode(
162 - nativeEventTarget,
163 - );
164 - if (
165 - targetInst !== null &&
166 - typeof targetInst.tag === 'number' &&
167 - !isFiberMounted(targetInst)
168 - ) {
169 - // If we get an event (ex: img onload) before committing that
170 - // component's mount, ignore it for now (that is, treat it as if it was an
171 - // event on a non-React tree). We might also consider queueing events and
172 - // dispatching them after the mount.
173 - targetInst = null;
174 - }
105 +export function setEnabled(enabled) {
106 + _enabled = !!enabled;
107 +}
108
176 - var bookKeeping = getTopLevelCallbackBookKeeping(
177 - topLevelType,
178 - nativeEvent,
179 - targetInst,
180 - );
109 +export function isEnabled() {
110 + return _enabled;
111 +}
112
182 - try {
183 - // Event queue being processed in the same cycle allows
184 - // `preventDefault`.
185 - ReactGenericBatching.batchedUpdates(handleTopLevelImpl, bookKeeping);
186 - } finally {
187 - releaseTopLevelCallbackBookKeeping(bookKeeping);
188 - }
189 - },
190 -};
113 +/**
114 + * Traps top-level events by using event bubbling.
115 + *
116 + * @param {string} topLevelType Record from `BrowserEventConstants`.
117 + * @param {string} handlerBaseName Event name (e.g. "click").
118 + * @param {object} element Element on which to attach listener.
119 + * @return {?object} An object with a remove function which will forcefully
120 + * remove the listener.
121 + * @internal
122 + */
123 +export function trapBubbledEvent(topLevelType, handlerBaseName, element) {
124 + if (!element) {
125 + return null;
126 + }
127 + return EventListener.listen(
128 + element,
129 + handlerBaseName,
130 + dispatchEvent.bind(null, topLevelType),
131 + );
132 +}
133
192 -export default ReactDOMEventListener;
134 +/**
135 + * Traps a top-level event by using event capturing.
136 + *
137 + * @param {string} topLevelType Record from `BrowserEventConstants`.
138 + * @param {string} handlerBaseName Event name (e.g. "click").
139 + * @param {object} element Element on which to attach listener.
140 + * @return {?object} An object with a remove function which will forcefully
141 + * remove the listener.
142 + * @internal
143 + */
144 +export function trapCapturedEvent(topLevelType, handlerBaseName, element) {
145 + if (!element) {
146 + return null;
147 + }
148 + return EventListener.capture(
149 + element,
150 + handlerBaseName,
151 + dispatchEvent.bind(null, topLevelType),
152 + );
153 +}
154 +
155 +export function dispatchEvent(topLevelType, nativeEvent) {
156 + if (!_enabled) {
157 + return;
158 + }
159 +
160 + var nativeEventTarget = getEventTarget(nativeEvent);
161 + var targetInst = getClosestInstanceFromNode(nativeEventTarget);
162 + if (
163 + targetInst !== null &&
164 + typeof targetInst.tag === 'number' &&
165 + !isFiberMounted(targetInst)
166 + ) {
167 + // If we get an event (ex: img onload) before committing that
168 + // component's mount, ignore it for now (that is, treat it as if it was an
169 + // event on a non-React tree). We might also consider queueing events and
170 + // dispatching them after the mount.
171 + targetInst = null;
172 + }
173 +
174 + var bookKeeping = getTopLevelCallbackBookKeeping(
175 + topLevelType,
176 + nativeEvent,
177 + targetInst,
178 + );
179 +
180 + try {
181 + // Event queue being processed in the same cycle allows
182 + // `preventDefault`.
183 + batchedUpdates(handleTopLevelImpl, bookKeeping);
184 + } finally {
185 + releaseTopLevelCallbackBookKeeping(bookKeeping);
186 + }
187 +}
packages/react-dom/src/events/SelectEventPlugin.js
+7 -12
@@ -5,15 +5,15 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import EventPropagators from 'events/EventPropagators';
8 +import {accumulateTwoPhaseDispatches} from 'events/EventPropagators';
9 import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
10 import SyntheticEvent from 'events/SyntheticEvent';
11 import isTextInputElement from 'shared/isTextInputElement';
12 import getActiveElement from 'fbjs/lib/getActiveElement';
13 import shallowEqual from 'fbjs/lib/shallowEqual';
14
15 -import ReactBrowserEventEmitter from './ReactBrowserEventEmitter';
16 -import ReactDOMComponentTree from '../client/ReactDOMComponentTree';
15 +import {isListeningToAllDependencies} from './ReactBrowserEventEmitter';
16 +import {getNodeFromInstance} from '../client/ReactDOMComponentTree';
17 import * as ReactInputSelection from '../client/ReactInputSelection';
18 import {DOCUMENT_NODE} from '../shared/HTMLNodeType';
19
@@ -46,11 +46,6 @@ var activeElementInst = null;
46 var lastSelection = null;
47 var mouseDown = false;
48
49 -// Track whether all listeners exists for this plugin. If none exist, we do
50 -// not extract events. See #3639.
51 -var isListeningToAllDependencies =
52 - ReactBrowserEventEmitter.isListeningToAllDependencies;
53 -
49 /**
50 * Get an object which is a unique representation of the current selection.
51 *
@@ -114,7 +109,7 @@ function constructSelectEvent(nativeEvent, nativeEventTarget) {
109 syntheticEvent.type = 'select';
110 syntheticEvent.target = activeElement;
111
117 - EventPropagators.accumulateTwoPhaseDispatches(syntheticEvent);
112 + accumulateTwoPhaseDispatches(syntheticEvent);
113
114 return syntheticEvent;
115 }
@@ -150,13 +145,13 @@ var SelectEventPlugin = {
145 : nativeEventTarget.nodeType === DOCUMENT_NODE
146 ? nativeEventTarget
147 : nativeEventTarget.ownerDocument;
148 + // Track whether all listeners exists for this plugin. If none exist, we do
149 + // not extract events. See #3639.
150 if (!doc || !isListeningToAllDependencies('onSelect', doc)) {
151 return null;
152 }
153
157 - var targetNode = targetInst
158 - ? ReactDOMComponentTree.getNodeFromInstance(targetInst)
159 - : window;
154 + var targetNode = targetInst ? getNodeFromInstance(targetInst) : window;
155
156 switch (topLevelType) {
157 // Track the input node that has focus.
packages/react-dom/src/events/SimpleEventPlugin.js
+2 -2
@@ -15,7 +15,7 @@ import type {
15 import type {Fiber} from 'react-reconciler/src/ReactFiber';
16 import type {EventTypes, PluginModule} from 'events/PluginModuleType';
17
18 -import EventPropagators from 'events/EventPropagators';
18 +import {accumulateTwoPhaseDispatches} from 'events/EventPropagators';
19 import SyntheticEvent from 'events/SyntheticEvent';
20 import warning from 'fbjs/lib/warning';
21
@@ -274,7 +274,7 @@ var SimpleEventPlugin: PluginModule<MouseEvent> = {
274 nativeEvent,
275 nativeEventTarget,
276 );
277 - EventPropagators.accumulateTwoPhaseDispatches(event);
277 + accumulateTwoPhaseDispatches(event);
278 return event;
279 },
280 };
packages/react-dom/src/events/TapEventPlugin.js
+3 -6
@@ -7,15 +7,12 @@
7 * @flow
8 */
9
10 -import EventPluginUtils from 'events/EventPluginUtils';
11 -import EventPropagators from 'events/EventPropagators';
10 +import {isStartish, isEndish} from 'events/EventPluginUtils';
11 +import {accumulateTwoPhaseDispatches} from 'events/EventPropagators';
12 import TouchEventUtils from 'fbjs/lib/TouchEventUtils';
13
14 import SyntheticUIEvent from './SyntheticUIEvent';
15
16 -var isStartish = EventPluginUtils.isStartish;
17 -var isEndish = EventPluginUtils.isEndish;
18 -
16 /**
17 * We are extending the Flow 'Touch' declaration to enable using bracket
18 * notation to access properties.
@@ -144,7 +141,7 @@ var TapEventPlugin = {
141 startCoords.x = 0;
142 startCoords.y = 0;
143 }
147 - EventPropagators.accumulateTwoPhaseDispatches(event);
144 + accumulateTwoPhaseDispatches(event);
145 return event;
146 },
147 };
packages/react-dom/src/events/__tests__/BeforeInputEventPlugin-test.js
+1 -1
@@ -49,7 +49,7 @@ describe('BeforeInputEventPlugin', function() {
49 this.ReactDOM = require('react-dom');
50
51 // TODO: can we express this test with only public API?
52 - this.ReactDOMComponentTree = require('../../client/ReactDOMComponentTree').default;
52 + this.ReactDOMComponentTree = require('../../client/ReactDOMComponentTree');
53 this.SyntheticCompositionEvent = require('../SyntheticCompositionEvent').default;
54 this.SyntheticInputEvent = require('../SyntheticInputEvent').default;
55 this.BeforeInputEventPlugin = require('../BeforeInputEventPlugin').default;
packages/react-dom/src/events/__tests__/FallbackCompositionState-test.js
+1 -1
@@ -16,7 +16,7 @@ describe('FallbackCompositionState', () => {
16
17 beforeEach(() => {
18 // TODO: can we express this test with only public API?
19 - FallbackCompositionState = require('../FallbackCompositionState').default;
19 + FallbackCompositionState = require('../FallbackCompositionState');
20 });
21
22 function getInput() {
packages/react-dom/src/events/__tests__/SelectEventPlugin-test.js
+1 -2
@@ -30,8 +30,7 @@ describe('SelectEventPlugin', () => {
30 ReactDOM = require('react-dom');
31 ReactTestUtils = require('react-dom/test-utils');
32 // TODO: can we express this test with only public API?
33 - ReactDOMComponentTree = require('../../client/ReactDOMComponentTree')
34 - .default;
33 + ReactDOMComponentTree = require('../../client/ReactDOMComponentTree');
34 SelectEventPlugin = require('../SelectEventPlugin').default;
35 });
36
packages/react-dom/src/server/DOMMarkupOperations.js
+65 -66
@@ -5,7 +5,15 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import DOMProperty from '../shared/DOMProperty';
8 +import {
9 + ATTRIBUTE_NAME_CHAR,
10 + ATTRIBUTE_NAME_START_CHAR,
11 + ID_ATTRIBUTE_NAME,
12 + ROOT_ATTRIBUTE_NAME,
13 + getPropertyInfo,
14 + shouldAttributeAcceptBooleanValue,
15 + shouldSetAttribute,
16 +} from '../shared/DOMProperty';
17 import quoteAttributeValueForBrowser
18 from '../shared/quoteAttributeValueForBrowser';
19 import warning from 'fbjs/lib/warning';
@@ -13,11 +21,7 @@ import warning from 'fbjs/lib/warning';
21 // isAttributeNameSafe() is currently duplicated in DOMPropertyOperations.
22 // TODO: Find a better place for this.
23 var VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
16 - '^[' +
17 - DOMProperty.ATTRIBUTE_NAME_START_CHAR +
18 - '][' +
19 - DOMProperty.ATTRIBUTE_NAME_CHAR +
20 - ']*$',
24 + '^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$',
25 );
26 var illegalAttributeNameCache = {};
27 var validatedAttributeNameCache = {};
@@ -54,70 +58,65 @@ function shouldIgnoreValue(propertyInfo, value) {
58 /**
59 * Operations for dealing with DOM properties.
60 */
57 -var DOMMarkupOperations = {
58 - /**
59 - * Creates markup for the ID property.
60 - *
61 - * @param {string} id Unescaped ID.
62 - * @return {string} Markup string.
63 - */
64 - createMarkupForID: function(id) {
65 - return (
66 - DOMProperty.ID_ATTRIBUTE_NAME + '=' + quoteAttributeValueForBrowser(id)
67 - );
68 - },
61
70 - createMarkupForRoot: function() {
71 - return DOMProperty.ROOT_ATTRIBUTE_NAME + '=""';
72 - },
62 +/**
63 + * Creates markup for the ID property.
64 + *
65 + * @param {string} id Unescaped ID.
66 + * @return {string} Markup string.
67 + */
68 +export function createMarkupForID(id) {
69 + return ID_ATTRIBUTE_NAME + '=' + quoteAttributeValueForBrowser(id);
70 +}
71
74 - /**
75 - * Creates markup for a property.
76 - *
77 - * @param {string} name
78 - * @param {*} value
79 - * @return {?string} Markup string, or null if the property was invalid.
80 - */
81 - createMarkupForProperty: function(name, value) {
82 - var propertyInfo = DOMProperty.getPropertyInfo(name);
83 - if (propertyInfo) {
84 - if (shouldIgnoreValue(propertyInfo, value)) {
85 - return '';
86 - }
87 - var attributeName = propertyInfo.attributeName;
88 - if (
89 - propertyInfo.hasBooleanValue ||
90 - (propertyInfo.hasOverloadedBooleanValue && value === true)
91 - ) {
92 - return attributeName + '=""';
93 - } else if (
94 - typeof value !== 'boolean' ||
95 - DOMProperty.shouldAttributeAcceptBooleanValue(name)
96 - ) {
97 - return attributeName + '=' + quoteAttributeValueForBrowser(value);
98 - }
99 - } else if (DOMProperty.shouldSetAttribute(name, value)) {
100 - if (value == null) {
101 - return '';
102 - }
103 - return name + '=' + quoteAttributeValueForBrowser(value);
104 - }
105 - return null;
106 - },
72 +export function createMarkupForRoot() {
73 + return ROOT_ATTRIBUTE_NAME + '=""';
74 +}
75
108 - /**
109 - * Creates markup for a custom property.
110 - *
111 - * @param {string} name
112 - * @param {*} value
113 - * @return {string} Markup string, or empty string if the property was invalid.
114 - */
115 - createMarkupForCustomAttribute: function(name, value) {
116 - if (!isAttributeNameSafe(name) || value == null) {
76 +/**
77 + * Creates markup for a property.
78 + *
79 + * @param {string} name
80 + * @param {*} value
81 + * @return {?string} Markup string, or null if the property was invalid.
82 + */
83 +export function createMarkupForProperty(name, value) {
84 + var propertyInfo = getPropertyInfo(name);
85 + if (propertyInfo) {
86 + if (shouldIgnoreValue(propertyInfo, value)) {
87 + return '';
88 + }
89 + var attributeName = propertyInfo.attributeName;
90 + if (
91 + propertyInfo.hasBooleanValue ||
92 + (propertyInfo.hasOverloadedBooleanValue && value === true)
93 + ) {
94 + return attributeName + '=""';
95 + } else if (
96 + typeof value !== 'boolean' ||
97 + shouldAttributeAcceptBooleanValue(name)
98 + ) {
99 + return attributeName + '=' + quoteAttributeValueForBrowser(value);
100 + }
101 + } else if (shouldSetAttribute(name, value)) {
102 + if (value == null) {
103 return '';
104 }
105 return name + '=' + quoteAttributeValueForBrowser(value);
120 - },
121 -};
106 + }
107 + return null;
108 +}
109
123 -export default DOMMarkupOperations;
110 +/**
111 + * Creates markup for a custom property.
112 + *
113 + * @param {string} name
114 + * @param {*} value
115 + * @return {string} Markup string, or empty string if the property was invalid.
116 + */
117 +export function createMarkupForCustomAttribute(name, value) {
118 + if (!isAttributeNameSafe(name) || value == null) {
119 + return '';
120 + }
121 + return name + '=' + quoteAttributeValueForBrowser(value);
122 +}
packages/react-dom/src/server/ReactPartialRenderer.js
+8 -7
@@ -20,7 +20,11 @@ import checkPropTypes from 'prop-types/checkPropTypes';
20 import describeComponentFrame from 'shared/describeComponentFrame';
21 import {ReactDebugCurrentFrame} from 'shared/ReactGlobalSharedState';
22
23 -import DOMMarkupOperations from './DOMMarkupOperations';
23 +import {
24 + createMarkupForCustomAttribute,
25 + createMarkupForProperty,
26 + createMarkupForRoot,
27 +} from './DOMMarkupOperations';
28 import {
29 Namespaces,
30 getIntrinsicNamespace,
@@ -319,13 +323,10 @@ function createOpenTagMarkup(
323 var markup = null;
324 if (isCustomComponent(tagLowercase, props)) {
325 if (!RESERVED_PROPS.hasOwnProperty(propKey)) {
322 - markup = DOMMarkupOperations.createMarkupForCustomAttribute(
323 - propKey,
324 - propValue,
325 - );
326 + markup = createMarkupForCustomAttribute(propKey, propValue);
327 }
328 } else {
328 - markup = DOMMarkupOperations.createMarkupForProperty(propKey, propValue);
329 + markup = createMarkupForProperty(propKey, propValue);
330 }
331 if (markup) {
332 ret += ' ' + markup;
@@ -339,7 +340,7 @@ function createOpenTagMarkup(
340 }
341
342 if (isRootElement) {
342 - ret += ' ' + DOMMarkupOperations.createMarkupForRoot();
343 + ret += ' ' + createMarkupForRoot();
344 }
345 return ret;
346 }
packages/react-dom/src/shared/DOMProperty.js
+95 -116
@@ -68,7 +68,7 @@ var DOMPropertyInjection = {
68
69 for (var propName in Properties) {
70 invariant(
71 - !DOMProperty.properties.hasOwnProperty(propName),
71 + !properties.hasOwnProperty(propName),
72 "injectDOMPropertyConfig(...): You're trying to inject DOM property " +
73 "'%s' which has already been injected. You may be accidentally " +
74 'injecting the same DOM property config twice, or you may be ' +
@@ -129,135 +129,114 @@ var DOMPropertyInjection = {
129 // without case-sensitivity. This allows the whitelist to pick up
130 // `allowfullscreen`, which should be written using the property configuration
131 // for `allowFullscreen`
132 - DOMProperty.properties[propName] = propertyInfo;
132 + properties[propName] = propertyInfo;
133 }
134 },
135 };
136
137 /* eslint-disable max-len */
138 -var ATTRIBUTE_NAME_START_CHAR =
138 +export const ATTRIBUTE_NAME_START_CHAR =
139 ':A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
140 /* eslint-enable max-len */
141 +export const ATTRIBUTE_NAME_CHAR =
142 + ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
143 +
144 +export const ID_ATTRIBUTE_NAME = 'data-reactid';
145 +export const ROOT_ATTRIBUTE_NAME = 'data-reactroot';
146
147 /**
143 - * DOMProperty exports lookup objects that can be used like functions:
144 - *
145 - * > DOMProperty.isValid['id']
146 - * true
147 - * > DOMProperty.isValid['foobar']
148 - * undefined
149 - *
150 - * Although this may be confusing, it performs better in general.
148 + * Map from property "standard name" to an object with info about how to set
149 + * the property in the DOM. Each object contains:
150 *
152 - * @see http://jsperf.com/key-exists
153 - * @see http://jsperf.com/key-missing
151 + * attributeName:
152 + * Used when rendering markup or with `*Attribute()`.
153 + * attributeNamespace
154 + * propertyName:
155 + * Used on DOM node instances. (This includes properties that mutate due to
156 + * external factors.)
157 + * mutationMethod:
158 + * If non-null, used instead of the property or `setAttribute()` after
159 + * initial render.
160 + * mustUseProperty:
161 + * Whether the property must be accessed and mutated as an object property.
162 + * hasBooleanValue:
163 + * Whether the property should be removed when set to a falsey value.
164 + * hasNumericValue:
165 + * Whether the property must be numeric or parse as a numeric and should be
166 + * removed when set to a falsey value.
167 + * hasPositiveNumericValue:
168 + * Whether the property must be positive numeric or parse as a positive
169 + * numeric and should be removed when set to a falsey value.
170 + * hasOverloadedBooleanValue:
171 + * Whether the property can be used as a flag as well as with a value.
172 + * Removed when strictly equal to false; present without a value when
173 + * strictly equal to true; present with a value otherwise.
174 */
155 -var DOMProperty = {
156 - ID_ATTRIBUTE_NAME: 'data-reactid',
157 - ROOT_ATTRIBUTE_NAME: 'data-reactroot',
158 -
159 - ATTRIBUTE_NAME_START_CHAR: ATTRIBUTE_NAME_START_CHAR,
160 - ATTRIBUTE_NAME_CHAR: ATTRIBUTE_NAME_START_CHAR +
161 - '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040',
162 -
163 - /**
164 - * Map from property "standard name" to an object with info about how to set
165 - * the property in the DOM. Each object contains:
166 - *
167 - * attributeName:
168 - * Used when rendering markup or with `*Attribute()`.
169 - * attributeNamespace
170 - * propertyName:
171 - * Used on DOM node instances. (This includes properties that mutate due to
172 - * external factors.)
173 - * mutationMethod:
174 - * If non-null, used instead of the property or `setAttribute()` after
175 - * initial render.
176 - * mustUseProperty:
177 - * Whether the property must be accessed and mutated as an object property.
178 - * hasBooleanValue:
179 - * Whether the property should be removed when set to a falsey value.
180 - * hasNumericValue:
181 - * Whether the property must be numeric or parse as a numeric and should be
182 - * removed when set to a falsey value.
183 - * hasPositiveNumericValue:
184 - * Whether the property must be positive numeric or parse as a positive
185 - * numeric and should be removed when set to a falsey value.
186 - * hasOverloadedBooleanValue:
187 - * Whether the property can be used as a flag as well as with a value.
188 - * Removed when strictly equal to false; present without a value when
189 - * strictly equal to true; present with a value otherwise.
190 - */
191 - properties: {},
175 +export const properties = {};
176
193 - /**
194 - * Checks whether a property name is a writeable attribute.
195 - * @method
196 - */
197 - shouldSetAttribute: function(name, value) {
198 - if (DOMProperty.isReservedProp(name)) {
199 - return false;
200 - }
201 - if (
202 - (name[0] === 'o' || name[0] === 'O') &&
203 - (name[1] === 'n' || name[1] === 'N') &&
204 - name.length > 2
205 - ) {
206 - return false;
207 - }
208 - if (value === null) {
177 +/**
178 + * Checks whether a property name is a writeable attribute.
179 + * @method
180 + */
181 +export function shouldSetAttribute(name, value) {
182 + if (isReservedProp(name)) {
183 + return false;
184 + }
185 + if (
186 + (name[0] === 'o' || name[0] === 'O') &&
187 + (name[1] === 'n' || name[1] === 'N') &&
188 + name.length > 2
189 + ) {
190 + return false;
191 + }
192 + if (value === null) {
193 + return true;
194 + }
195 + switch (typeof value) {
196 + case 'boolean':
197 + return shouldAttributeAcceptBooleanValue(name);
198 + case 'undefined':
199 + case 'number':
200 + case 'string':
201 + case 'object':
202 return true;
210 - }
211 - switch (typeof value) {
212 - case 'boolean':
213 - return DOMProperty.shouldAttributeAcceptBooleanValue(name);
214 - case 'undefined':
215 - case 'number':
216 - case 'string':
217 - case 'object':
218 - return true;
219 - default:
220 - // function, symbol
221 - return false;
222 - }
223 - },
224 -
225 - getPropertyInfo(name) {
226 - return DOMProperty.properties.hasOwnProperty(name)
227 - ? DOMProperty.properties[name]
228 - : null;
229 - },
203 + default:
204 + // function, symbol
205 + return false;
206 + }
207 +}
208
231 - shouldAttributeAcceptBooleanValue(name) {
232 - if (DOMProperty.isReservedProp(name)) {
233 - return true;
234 - }
235 - let propertyInfo = DOMProperty.getPropertyInfo(name);
236 - if (propertyInfo) {
237 - return (
238 - propertyInfo.hasBooleanValue ||
239 - propertyInfo.hasStringBooleanValue ||
240 - propertyInfo.hasOverloadedBooleanValue
241 - );
242 - }
243 - var prefix = name.toLowerCase().slice(0, 5);
244 - return prefix === 'data-' || prefix === 'aria-';
245 - },
209 +export function getPropertyInfo(name) {
210 + return properties.hasOwnProperty(name) ? properties[name] : null;
211 +}
212
247 - /**
248 - * Checks to see if a property name is within the list of properties
249 - * reserved for internal React operations. These properties should
250 - * not be set on an HTML element.
251 - *
252 - * @private
253 - * @param {string} name
254 - * @return {boolean} If the name is within reserved props
255 - */
256 - isReservedProp(name) {
257 - return RESERVED_PROPS.hasOwnProperty(name);
258 - },
213 +export function shouldAttributeAcceptBooleanValue(name) {
214 + if (isReservedProp(name)) {
215 + return true;
216 + }
217 + let propertyInfo = getPropertyInfo(name);
218 + if (propertyInfo) {
219 + return (
220 + propertyInfo.hasBooleanValue ||
221 + propertyInfo.hasStringBooleanValue ||
222 + propertyInfo.hasOverloadedBooleanValue
223 + );
224 + }
225 + var prefix = name.toLowerCase().slice(0, 5);
226 + return prefix === 'data-' || prefix === 'aria-';
227 +}
228
260 - injection: DOMPropertyInjection,
261 -};
229 +/**
230 + * Checks to see if a property name is within the list of properties
231 + * reserved for internal React operations. These properties should
232 + * not be set on an HTML element.
233 + *
234 + * @private
235 + * @param {string} name
236 + * @return {boolean} If the name is within reserved props
237 + */
238 +export function isReservedProp(name) {
239 + return RESERVED_PROPS.hasOwnProperty(name);
240 +}
241
263 -export default DOMProperty;
242 +export const injection = DOMPropertyInjection;
packages/react-dom/src/shared/HTMLDOMPropertyConfig.js
+7 -9
@@ -5,16 +5,14 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import DOMProperty from './DOMProperty';
8 +import {injection} from './DOMProperty';
9
10 -var MUST_USE_PROPERTY = DOMProperty.injection.MUST_USE_PROPERTY;
11 -var HAS_BOOLEAN_VALUE = DOMProperty.injection.HAS_BOOLEAN_VALUE;
12 -var HAS_NUMERIC_VALUE = DOMProperty.injection.HAS_NUMERIC_VALUE;
13 -var HAS_POSITIVE_NUMERIC_VALUE =
14 - DOMProperty.injection.HAS_POSITIVE_NUMERIC_VALUE;
15 -var HAS_OVERLOADED_BOOLEAN_VALUE =
16 - DOMProperty.injection.HAS_OVERLOADED_BOOLEAN_VALUE;
17 -var HAS_STRING_BOOLEAN_VALUE = DOMProperty.injection.HAS_STRING_BOOLEAN_VALUE;
10 +var MUST_USE_PROPERTY = injection.MUST_USE_PROPERTY;
11 +var HAS_BOOLEAN_VALUE = injection.HAS_BOOLEAN_VALUE;
12 +var HAS_NUMERIC_VALUE = injection.HAS_NUMERIC_VALUE;
13 +var HAS_POSITIVE_NUMERIC_VALUE = injection.HAS_POSITIVE_NUMERIC_VALUE;
14 +var HAS_OVERLOADED_BOOLEAN_VALUE = injection.HAS_OVERLOADED_BOOLEAN_VALUE;
15 +var HAS_STRING_BOOLEAN_VALUE = injection.HAS_STRING_BOOLEAN_VALUE;
16
17 var HTMLDOMPropertyConfig = {
18 // When adding attributes to this list, be sure to also add them to
packages/react-dom/src/shared/ReactDOMInjection.js
+1 -1
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import DOMProperty from './DOMProperty';
8 +import * as DOMProperty from './DOMProperty';
9 import HTMLDOMPropertyConfig from './HTMLDOMPropertyConfig';
10 import SVGDOMPropertyConfig from './SVGDOMPropertyConfig';
11
packages/react-dom/src/shared/ReactDOMInvalidARIAHook.js
+3 -5
@@ -8,15 +8,13 @@
8 import warning from 'fbjs/lib/warning';
9 import {ReactDebugCurrentFrame} from 'shared/ReactGlobalSharedState';
10
11 -import DOMProperty from './DOMProperty';
11 +import {ATTRIBUTE_NAME_CHAR} from './DOMProperty';
12 import isCustomComponent from './isCustomComponent';
13 import validAriaProperties from './validAriaProperties';
14
15 var warnedProperties = {};
16 -var rARIA = new RegExp('^(aria)-[' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$');
17 -var rARIACamel = new RegExp(
18 - '^(aria)[A-Z][' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$',
19 -);
16 +var rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
17 +var rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
18
19 var hasOwnProperty = Object.prototype.hasOwnProperty;
20
packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js
+20 -16
@@ -5,11 +5,20 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import EventPluginRegistry from 'events/EventPluginRegistry';
8 +import {
9 + registrationNameModules,
10 + plugins,
11 + possibleRegistrationNames,
12 +} from 'events/EventPluginRegistry';
13 import {ReactDebugCurrentFrame} from 'shared/ReactGlobalSharedState';
14 import warning from 'fbjs/lib/warning';
15
12 -import DOMProperty from './DOMProperty';
16 +import {
17 + ATTRIBUTE_NAME_CHAR,
18 + isReservedProp,
19 + shouldAttributeAcceptBooleanValue,
20 + shouldSetAttribute,
21 +} from './DOMProperty';
22 import isCustomComponent from './isCustomComponent';
23 import possibleStandardNames from './possibleStandardNames';
24
@@ -22,34 +31,29 @@ if (__DEV__) {
31 var warnedProperties = {};
32 var hasOwnProperty = Object.prototype.hasOwnProperty;
33 var EVENT_NAME_REGEX = /^on[A-Z]/;
25 - var rARIA = new RegExp('^(aria)-[' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$');
26 - var rARIACamel = new RegExp(
27 - '^(aria)[A-Z][' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$',
28 - );
34 + var rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
35 + var rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
36
37 var validateProperty = function(tagName, name, value) {
38 if (hasOwnProperty.call(warnedProperties, name) && warnedProperties[name]) {
39 return true;
40 }
41
35 - if (EventPluginRegistry.registrationNameModules.hasOwnProperty(name)) {
42 + if (registrationNameModules.hasOwnProperty(name)) {
43 return true;
44 }
45
39 - if (
40 - EventPluginRegistry.plugins.length === 0 &&
41 - EVENT_NAME_REGEX.test(name)
42 - ) {
46 + if (plugins.length === 0 && EVENT_NAME_REGEX.test(name)) {
47 // If no event plugins have been injected, we might be in a server environment.
48 // Don't check events in this case.
49 return true;
50 }
51
52 var lowerCasedName = name.toLowerCase();
49 - var registrationName = EventPluginRegistry.possibleRegistrationNames.hasOwnProperty(
53 + var registrationName = possibleRegistrationNames.hasOwnProperty(
54 lowerCasedName,
55 )
52 - ? EventPluginRegistry.possibleRegistrationNames[lowerCasedName]
56 + ? possibleRegistrationNames[lowerCasedName]
57 : null;
58
59 if (registrationName != null) {
@@ -140,7 +144,7 @@ if (__DEV__) {
144 return true;
145 }
146
143 - const isReserved = DOMProperty.isReservedProp(name);
147 + const isReserved = isReservedProp(name);
148
149 // Known attributes should match the casing specified in the property config.
150 if (possibleStandardNames.hasOwnProperty(lowerCasedName)) {
@@ -176,7 +180,7 @@ if (__DEV__) {
180
181 if (
182 typeof value === 'boolean' &&
179 - !DOMProperty.shouldAttributeAcceptBooleanValue(name)
183 + !shouldAttributeAcceptBooleanValue(name)
184 ) {
185 if (value) {
186 warning(
@@ -220,7 +224,7 @@ if (__DEV__) {
224 }
225
226 // Warn when a known attribute is a bad type
223 - if (!DOMProperty.shouldSetAttribute(name, value)) {
227 + if (!shouldSetAttribute(name, value)) {
228 warnedProperties[name] = true;
229 return false;
230 }
packages/react-dom/src/shared/SVGDOMPropertyConfig.js
+2 -2
@@ -5,9 +5,9 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import DOMProperty from './DOMProperty';
8 +import {injection} from './DOMProperty';
9
10 -var {HAS_STRING_BOOLEAN_VALUE} = DOMProperty.injection;
10 +var {HAS_STRING_BOOLEAN_VALUE} = injection;
11
12 var NS = {
13 xlink: 'http://www.w3.org/1999/xlink',
packages/react-dom/src/unstable-native-dependencies/ReactDOMUnstableNativeDependencies.js
+1 -1
@@ -6,7 +6,7 @@
6 */
7
8 import ReactDOM from 'react-dom';
9 -import EventPluginUtils from 'events/EventPluginUtils';
9 +import * as EventPluginUtils from 'events/EventPluginUtils';
10 import ResponderEventPlugin from 'events/ResponderEventPlugin';
11 import ResponderTouchHistoryStore from 'events/ResponderTouchHistoryStore';
12
packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js
+6 -3
@@ -9,7 +9,10 @@
9
10 import type {ReactNativeBaseComponentViewConfig} from './ReactNativeTypes';
11
12 -import EventPropagators from 'events/EventPropagators';
12 +import {
13 + accumulateTwoPhaseDispatches,
14 + accumulateDirectDispatches,
15 +} from 'events/EventPropagators';
16 import SyntheticEvent from 'events/SyntheticEvent';
17 import invariant from 'fbjs/lib/invariant';
18
@@ -42,9 +45,9 @@ const ReactNativeBridgeEventPlugin = {
45 nativeEventTarget,
46 );
47 if (bubbleDispatchConfig) {
45 - EventPropagators.accumulateTwoPhaseDispatches(event);
48 + accumulateTwoPhaseDispatches(event);
49 } else if (directDispatchConfig) {
47 - EventPropagators.accumulateDirectDispatches(event);
50 + accumulateDirectDispatches(event);
51 } else {
52 return null;
53 }
packages/react-native-renderer/src/ReactNativeComponentTree.js
+10 -16
@@ -10,11 +10,11 @@ import invariant from 'fbjs/lib/invariant';
10 var instanceCache = {};
11 var instanceProps = {};
12
13 -function precacheFiberNode(hostInst, tag) {
13 +export function precacheFiberNode(hostInst, tag) {
14 instanceCache[tag] = hostInst;
15 }
16
17 -function uncacheFiberNode(tag) {
17 +export function uncacheFiberNode(tag) {
18 delete instanceCache[tag];
19 delete instanceProps[tag];
20 }
@@ -29,22 +29,16 @@ function getTagFromInstance(inst) {
29 return tag;
30 }
31
32 -function getFiberCurrentPropsFromNode(stateNode) {
32 +export {
33 + getInstanceFromTag as getClosestInstanceFromNode,
34 + getInstanceFromTag as getInstanceFromNode,
35 + getTagFromInstance as getNodeFromInstance,
36 +};
37 +
38 +export function getFiberCurrentPropsFromNode(stateNode) {
39 return instanceProps[stateNode._nativeTag] || null;
40 }
41
36 -function updateFiberProps(tag, props) {
42 +export function updateFiberProps(tag, props) {
43 instanceProps[tag] = props;
44 }
39 -
40 -var ReactNativeComponentTree = {
41 - getClosestInstanceFromNode: getInstanceFromTag,
42 - getInstanceFromNode: getInstanceFromTag,
43 - getNodeFromInstance: getTagFromInstance,
44 - precacheFiberNode,
45 - uncacheFiberNode,
46 - getFiberCurrentPropsFromNode,
47 - updateFiberProps,
48 -};
49 -
50 -export default ReactNativeComponentTree;
packages/react-native-renderer/src/ReactNativeEventEmitter.js
+100 -119
@@ -7,15 +7,18 @@
7 * @flow
8 */
9
10 -import EventPluginHub from 'events/EventPluginHub';
11 -import EventPluginRegistry from 'events/EventPluginRegistry';
12 -import ReactEventEmitterMixin from 'events/ReactEventEmitterMixin';
13 -import ReactGenericBatching from 'events/ReactGenericBatching';
10 +import {getListener} from 'events/EventPluginHub';
11 +import {registrationNameModules} from 'events/EventPluginRegistry';
12 +import {batchedUpdates} from 'events/ReactGenericBatching';
13 +import {handleTopLevel} from 'events/ReactEventEmitterMixin';
14 import warning from 'fbjs/lib/warning';
15
16 -import ReactNativeComponentTree from './ReactNativeComponentTree';
16 +import {getInstanceFromNode} from './ReactNativeComponentTree';
17 import ReactNativeTagHandles from './ReactNativeTagHandles';
18
19 +export * from 'events/ReactEventEmitterMixin';
20 +export {getListener, registrationNameModules as registrationNames};
21 +
22 /**
23 * Version of `ReactBrowserEventEmitter` that works on the receiving side of a
24 * serialized worker boundary.
@@ -74,123 +77,101 @@ var removeTouchesAtIndices = function(
77 return rippedOut;
78 };
79
77 -var ReactNativeEventEmitter = {
78 - ...ReactEventEmitterMixin,
79 -
80 - registrationNames: EventPluginRegistry.registrationNameModules,
81 -
82 - getListener: EventPluginHub.getListener,
83 -
84 - /**
85 - * Internal version of `receiveEvent` in terms of normalized (non-tag)
86 - * `rootNodeID`.
87 - *
88 - * @see receiveEvent.
89 - *
90 - * @param {rootNodeID} rootNodeID React root node ID that event occurred on.
91 - * @param {TopLevelType} topLevelType Top level type of event.
92 - * @param {?object} nativeEventParam Object passed from native.
93 - */
94 - _receiveRootNodeIDEvent: function(
95 - rootNodeID: number,
96 - topLevelType: string,
97 - nativeEventParam: ?Object,
98 - ) {
99 - var nativeEvent = nativeEventParam || EMPTY_NATIVE_EVENT;
100 - var inst = ReactNativeComponentTree.getInstanceFromNode(rootNodeID);
101 - ReactGenericBatching.batchedUpdates(function() {
102 - ReactNativeEventEmitter.handleTopLevel(
103 - topLevelType,
104 - inst,
105 - nativeEvent,
106 - nativeEvent.target,
107 - );
108 - });
109 - // React Native doesn't use ReactControlledComponent but if it did, here's
110 - // where it would do it.
111 - },
80 +/**
81 + * Internal version of `receiveEvent` in terms of normalized (non-tag)
82 + * `rootNodeID`.
83 + *
84 + * @see receiveEvent.
85 + *
86 + * @param {rootNodeID} rootNodeID React root node ID that event occurred on.
87 + * @param {TopLevelType} topLevelType Top level type of event.
88 + * @param {?object} nativeEventParam Object passed from native.
89 + */
90 +export function _receiveRootNodeIDEvent(
91 + rootNodeID: number,
92 + topLevelType: string,
93 + nativeEventParam: ?Object,
94 +) {
95 + var nativeEvent = nativeEventParam || EMPTY_NATIVE_EVENT;
96 + var inst = getInstanceFromNode(rootNodeID);
97 + batchedUpdates(function() {
98 + handleTopLevel(topLevelType, inst, nativeEvent, nativeEvent.target);
99 + });
100 + // React Native doesn't use ReactControlledComponent but if it did, here's
101 + // where it would do it.
102 +}
103
113 - /**
114 - * Publicly exposed method on module for native objc to invoke when a top
115 - * level event is extracted.
116 - * @param {rootNodeID} rootNodeID React root node ID that event occurred on.
117 - * @param {TopLevelType} topLevelType Top level type of event.
118 - * @param {object} nativeEventParam Object passed from native.
119 - */
120 - receiveEvent: function(
121 - rootNodeID: number,
122 - topLevelType: string,
123 - nativeEventParam: Object,
124 - ) {
125 - ReactNativeEventEmitter._receiveRootNodeIDEvent(
126 - rootNodeID,
127 - topLevelType,
128 - nativeEventParam,
129 - );
130 - },
104 +/**
105 + * Publicly exposed method on module for native objc to invoke when a top
106 + * level event is extracted.
107 + * @param {rootNodeID} rootNodeID React root node ID that event occurred on.
108 + * @param {TopLevelType} topLevelType Top level type of event.
109 + * @param {object} nativeEventParam Object passed from native.
110 + */
111 +export function receiveEvent(
112 + rootNodeID: number,
113 + topLevelType: string,
114 + nativeEventParam: Object,
115 +) {
116 + _receiveRootNodeIDEvent(rootNodeID, topLevelType, nativeEventParam);
117 +}
118
132 - /**
133 - * Simple multi-wrapper around `receiveEvent` that is intended to receive an
134 - * efficient representation of `Touch` objects, and other information that
135 - * can be used to construct W3C compliant `Event` and `Touch` lists.
136 - *
137 - * This may create dispatch behavior that differs than web touch handling. We
138 - * loop through each of the changed touches and receive it as a single event.
139 - * So two `touchStart`/`touchMove`s that occur simultaneously are received as
140 - * two separate touch event dispatches - when they arguably should be one.
141 - *
142 - * This implementation reuses the `Touch` objects themselves as the `Event`s
143 - * since we dispatch an event for each touch (though that might not be spec
144 - * compliant). The main purpose of reusing them is to save allocations.
145 - *
146 - * TODO: Dispatch multiple changed touches in one event. The bubble path
147 - * could be the first common ancestor of all the `changedTouches`.
148 - *
149 - * One difference between this behavior and W3C spec: cancelled touches will
150 - * not appear in `.touches`, or in any future `.touches`, though they may
151 - * still be "actively touching the surface".
152 - *
153 - * Web desktop polyfills only need to construct a fake touch event with
154 - * identifier 0, also abandoning traditional click handlers.
155 - */
156 - receiveTouches: function(
157 - eventTopLevelType: string,
158 - touches: Array<Object>,
159 - changedIndices: Array<number>,
160 - ) {
161 - var changedTouches = eventTopLevelType === 'topTouchEnd' ||
162 - eventTopLevelType === 'topTouchCancel'
163 - ? removeTouchesAtIndices(touches, changedIndices)
164 - : touchSubsequence(touches, changedIndices);
119 +/**
120 + * Simple multi-wrapper around `receiveEvent` that is intended to receive an
121 + * efficient representation of `Touch` objects, and other information that
122 + * can be used to construct W3C compliant `Event` and `Touch` lists.
123 + *
124 + * This may create dispatch behavior that differs than web touch handling. We
125 + * loop through each of the changed touches and receive it as a single event.
126 + * So two `touchStart`/`touchMove`s that occur simultaneously are received as
127 + * two separate touch event dispatches - when they arguably should be one.
128 + *
129 + * This implementation reuses the `Touch` objects themselves as the `Event`s
130 + * since we dispatch an event for each touch (though that might not be spec
131 + * compliant). The main purpose of reusing them is to save allocations.
132 + *
133 + * TODO: Dispatch multiple changed touches in one event. The bubble path
134 + * could be the first common ancestor of all the `changedTouches`.
135 + *
136 + * One difference between this behavior and W3C spec: cancelled touches will
137 + * not appear in `.touches`, or in any future `.touches`, though they may
138 + * still be "actively touching the surface".
139 + *
140 + * Web desktop polyfills only need to construct a fake touch event with
141 + * identifier 0, also abandoning traditional click handlers.
142 + */
143 +export function receiveTouches(
144 + eventTopLevelType: string,
145 + touches: Array<Object>,
146 + changedIndices: Array<number>,
147 +) {
148 + var changedTouches = eventTopLevelType === 'topTouchEnd' ||
149 + eventTopLevelType === 'topTouchCancel'
150 + ? removeTouchesAtIndices(touches, changedIndices)
151 + : touchSubsequence(touches, changedIndices);
152
166 - for (var jj = 0; jj < changedTouches.length; jj++) {
167 - var touch = changedTouches[jj];
168 - // Touch objects can fulfill the role of `DOM` `Event` objects if we set
169 - // the `changedTouches`/`touches`. This saves allocations.
170 - touch.changedTouches = changedTouches;
171 - touch.touches = touches;
172 - var nativeEvent = touch;
173 - var rootNodeID = null;
174 - var target = nativeEvent.target;
175 - if (target !== null && target !== undefined) {
176 - if (target < ReactNativeTagHandles.tagsStartAt) {
177 - if (__DEV__) {
178 - warning(
179 - false,
180 - 'A view is reporting that a touch occurred on tag zero.',
181 - );
182 - }
183 - } else {
184 - rootNodeID = target;
153 + for (var jj = 0; jj < changedTouches.length; jj++) {
154 + var touch = changedTouches[jj];
155 + // Touch objects can fulfill the role of `DOM` `Event` objects if we set
156 + // the `changedTouches`/`touches`. This saves allocations.
157 + touch.changedTouches = changedTouches;
158 + touch.touches = touches;
159 + var nativeEvent = touch;
160 + var rootNodeID = null;
161 + var target = nativeEvent.target;
162 + if (target !== null && target !== undefined) {
163 + if (target < ReactNativeTagHandles.tagsStartAt) {
164 + if (__DEV__) {
165 + warning(
166 + false,
167 + 'A view is reporting that a touch occurred on tag zero.',
168 + );
169 }
170 + } else {
171 + rootNodeID = target;
172 }
187 - ReactNativeEventEmitter._receiveRootNodeIDEvent(
188 - rootNodeID,
189 - eventTopLevelType,
190 - nativeEvent,
191 - );
173 }
193 - },
194 -};
195 -
196 -export default ReactNativeEventEmitter;
174 + // $FlowFixMe Shouldn't we *not* call it if rootNodeID is null?
175 + _receiveRootNodeIDEvent(rootNodeID, eventTopLevelType, nativeEvent);
176 + }
177 +}
packages/react-native-renderer/src/ReactNativeFiberInspector.js
+1 -2
@@ -20,9 +20,8 @@ import invariant from 'fbjs/lib/invariant';
20 // Module provided by RN:
21 import UIManager from 'UIManager';
22
23 -import ReactNativeComponentTree from './ReactNativeComponentTree';
23 +import {getClosestInstanceFromNode} from './ReactNativeComponentTree';
24
25 -const {getClosestInstanceFromNode} = ReactNativeComponentTree;
25 let getInspectorDataForViewTag;
26
27 if (__DEV__) {
packages/react-native-renderer/src/ReactNativeFiberRenderer.js
+5 -7
@@ -20,16 +20,14 @@ import deepFreezeAndThrowOnMutationInDev
20 import * as ReactNativeViewConfigRegistry
21 from './ReactNativeViewConfigRegistry';
22 import * as ReactNativeAttributePayload from './ReactNativeAttributePayload';
23 -import ReactNativeComponentTree from './ReactNativeComponentTree';
24 -import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent';
25 -import * as ReactNativeFrameScheduling from './ReactNativeFrameScheduling';
26 -import ReactNativeTagHandles from './ReactNativeTagHandles';
27 -
28 -const {
23 +import {
24 precacheFiberNode,
25 uncacheFiberNode,
26 updateFiberProps,
32 -} = ReactNativeComponentTree;
27 +} from './ReactNativeComponentTree';
28 +import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent';
29 +import * as ReactNativeFrameScheduling from './ReactNativeFrameScheduling';
30 +import ReactNativeTagHandles from './ReactNativeTagHandles';
31
32 export type Container = number;
33 export type Instance = {
packages/react-native-renderer/src/ReactNativeInjection.js
+4 -4
@@ -16,15 +16,15 @@
16 // Module provided by RN:
17 import 'InitializeCore';
18
19 -import EventPluginHub from 'events/EventPluginHub';
20 -import EventPluginUtils from 'events/EventPluginUtils';
19 +import * as EventPluginHub from 'events/EventPluginHub';
20 +import * as EventPluginUtils from 'events/EventPluginUtils';
21 import ResponderEventPlugin from 'events/ResponderEventPlugin';
22 // Module provided by RN:
23 import RCTEventEmitter from 'RCTEventEmitter';
24
25 import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
26 -import ReactNativeComponentTree from './ReactNativeComponentTree';
27 -import ReactNativeEventEmitter from './ReactNativeEventEmitter';
26 +import * as ReactNativeComponentTree from './ReactNativeComponentTree';
27 +import * as ReactNativeEventEmitter from './ReactNativeEventEmitter';
28 import ReactNativeEventPluginOrder from './ReactNativeEventPluginOrder';
29 import ReactNativeGlobalResponderHandler
30 from './ReactNativeGlobalResponderHandler';
packages/react-native-renderer/src/ReactNativeRenderer.js
+2 -2
@@ -17,7 +17,7 @@ import * as ReactFiberErrorLogger
17 from 'react-reconciler/src/ReactFiberErrorLogger';
18 import * as ReactPortal from 'react-reconciler/src/ReactPortal';
19 import {injectInternals} from 'react-reconciler/src/ReactFiberDevToolsHook';
20 -import ReactGenericBatching from 'events/ReactGenericBatching';
20 +import * as ReactGenericBatching from 'events/ReactGenericBatching';
21 import TouchHistoryMath from 'events/TouchHistoryMath';
22 import * as ReactGlobalSharedState from 'shared/ReactGlobalSharedState';
23 import ReactVersion from 'shared/ReactVersion';
@@ -28,7 +28,7 @@ import {showDialog} from './ReactNativeFiberErrorDialog';
28 import NativeMethodsMixin from './NativeMethodsMixin';
29 import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
30 import ReactNativeComponent from './ReactNativeComponent';
31 -import ReactNativeComponentTree from './ReactNativeComponentTree';
31 +import * as ReactNativeComponentTree from './ReactNativeComponentTree';
32 import ReactNativeFiberRenderer from './ReactNativeFiberRenderer';
33 import ReactNativePropRegistry from './ReactNativePropRegistry';
34 import {getInspectorDataForViewTag} from './ReactNativeFiberInspector';
packages/react-rt-renderer/src/ReactNativeRT.js
+3 -3
@@ -18,10 +18,10 @@ import {
18 } from 'react-native-renderer/src/ReactNativeFiberErrorDialog';
19 import * as ReactPortal from 'react-reconciler/src/ReactPortal';
20 import {injectInternals} from 'react-reconciler/src/ReactFiberDevToolsHook';
21 -import ReactGenericBatching from 'events/ReactGenericBatching';
21 +import * as ReactGenericBatching from 'events/ReactGenericBatching';
22 import ReactVersion from 'shared/ReactVersion';
23
24 -import ReactNativeRTComponentTree from './ReactNativeRTComponentTree';
24 +import {getFiberFromTag} from './ReactNativeRTComponentTree';
25 import ReactNativeRTFiberRenderer from './ReactNativeRTFiberRenderer';
26 import ReactNativeRTFiberInspector from './ReactNativeRTFiberInspector';
27
@@ -84,7 +84,7 @@ const ReactNativeRTFiber: ReactNativeRTType = {
84 };
85
86 injectInternals({
87 - findFiberByHostInstance: ReactNativeRTComponentTree.getFiberFromTag,
87 + findFiberByHostInstance: getFiberFromTag,
88 findHostInstanceByFiber: ReactNativeRTFiberRenderer.findHostInstance,
89 getInspectorDataForViewTag: ReactNativeRTFiberInspector.getInspectorDataForViewTag,
90 // This is an enum because we may add more (e.g. profiler build)
packages/react-rt-renderer/src/ReactNativeRTComponentTree.js
+5 -15
@@ -12,33 +12,23 @@ import type {Fiber} from 'react-reconciler/src/ReactFiber';
12 var instanceCache: {[key: number]: Fiber} = {};
13 var instanceProps: {[key: number]: Object} = {};
14
15 -function precacheFiberNode(fiber: Fiber, tag: number): void {
15 +export function precacheFiberNode(fiber: Fiber, tag: number): void {
16 instanceCache[tag] = fiber;
17 }
18
19 -function getFiberFromTag(tag: number): null | Fiber {
19 +export function getFiberFromTag(tag: number): null | Fiber {
20 return instanceCache[tag] || null;
21 }
22
23 -function uncacheFiberNode(tag: number): void {
23 +export function uncacheFiberNode(tag: number): void {
24 delete instanceCache[tag];
25 delete instanceProps[tag];
26 }
27
28 -function getFiberCurrentPropsFromTag(tag: number): null | Object {
28 +export function getFiberCurrentPropsFromTag(tag: number): null | Object {
29 return instanceProps[tag] || null;
30 }
31
32 -function updateFiberProps(tag: number, props: Object): void {
32 +export function updateFiberProps(tag: number, props: Object): void {
33 instanceProps[tag] = props;
34 }
35 -
36 -var ReactNativeRTComponentTree = {
37 - precacheFiberNode,
38 - uncacheFiberNode,
39 - getFiberFromTag,
40 - getFiberCurrentPropsFromTag,
41 - updateFiberProps,
42 -};
43 -
44 -export default ReactNativeRTComponentTree;
packages/react-rt-renderer/src/ReactNativeRTEventEmitter.js
+4 -4
@@ -7,11 +7,11 @@
7 * @flow
8 */
9
10 -import ReactGenericBatching from 'events/ReactGenericBatching';
10 +import {batchedUpdates} from 'events/ReactGenericBatching';
11 // Module provided by RN:
12 import BatchedBridge from 'BatchedBridge';
13
14 -import ReactNativeRTComponentTree from './ReactNativeRTComponentTree';
14 +import {getFiberCurrentPropsFromTag} from './ReactNativeRTComponentTree';
15
16 var ReactNativeRTEventEmitter = {
17 /**
@@ -27,7 +27,7 @@ var ReactNativeRTEventEmitter = {
27 nativeEventParam: Object,
28 ) {
29 var nativeEvent = nativeEventParam;
30 - var props = ReactNativeRTComponentTree.getFiberCurrentPropsFromTag(tag);
30 + var props = getFiberCurrentPropsFromTag(tag);
31 if (props == null) {
32 return;
33 }
@@ -35,7 +35,7 @@ var ReactNativeRTEventEmitter = {
35 if (typeof eventHandler !== 'function') {
36 return;
37 }
38 - ReactGenericBatching.batchedUpdates(function() {
38 + batchedUpdates(function() {
39 eventHandler(nativeEvent);
40 });
41 },
packages/react-rt-renderer/src/ReactNativeRTFiberInspector.js
+1 -2
@@ -16,9 +16,8 @@ import {HostComponent} from 'shared/ReactTypeOfWork';
16 import emptyObject from 'fbjs/lib/emptyObject';
17 import invariant from 'fbjs/lib/invariant';
18
19 -import ReactNativeRTComponentTree from './ReactNativeRTComponentTree';
19 +import {getFiberFromTag} from './ReactNativeRTComponentTree';
20
21 -const {getFiberFromTag} = ReactNativeRTComponentTree;
21 let getInspectorDataForViewTag;
22
23 if (__DEV__) {
packages/react-rt-renderer/src/ReactNativeRTFiberRenderer.js
+4 -3
@@ -13,7 +13,10 @@ import invariant from 'fbjs/lib/invariant';
13 // Module provided by RN:
14 import RTManager from 'RTManager';
15
16 -import ReactNativeRTComponentTree from './ReactNativeRTComponentTree';
16 +import {
17 + precacheFiberNode,
18 + updateFiberProps,
19 +} from './ReactNativeRTComponentTree';
20 import ReactNativeRTTagHandles from './ReactNativeRTTagHandles';
21
22 export type Container = number;
@@ -21,8 +24,6 @@ export type Instance = number;
24 export type Props = Object;
25 export type TextInstance = number;
26
24 -const {precacheFiberNode, updateFiberProps} = ReactNativeRTComponentTree;
25 -
27 function processProps(instance: number, props: Props): Object {
28 const propsPayload = {};
29 for (var key in props) {
packages/react-test-renderer/src/ReactTestRenderer.js
+2 -2
@@ -11,7 +11,7 @@ import type {Fiber} from 'react-reconciler/src/ReactFiber';
11 import type {FiberRoot} from 'react-reconciler/src/ReactFiberRoot';
12
13 import ReactFiberReconciler from 'react-reconciler';
14 -import ReactGenericBatching from 'events/ReactGenericBatching';
14 +import {batchedUpdates} from 'events/ReactGenericBatching';
15 import {findCurrentFiberUsingSlowPath} from 'shared/ReactFiberTreeReflection';
16 import emptyObject from 'fbjs/lib/emptyObject';
17 import {
@@ -633,7 +633,7 @@ var ReactTestRendererFiber = {
633 },
634
635 /* eslint-disable camelcase */
636 - unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,
636 + unstable_batchedUpdates: batchedUpdates,
637 /* eslint-enable camelcase */
638 };
639
scripts/rollup/results.json
+58 -58
@@ -25,28 +25,28 @@
25 "gzip": 6870
26 },
27 "react-dom.development.js (UMD_DEV)": {
28 - "size": 596493,
29 - "gzip": 134889
28 + "size": 589183,
29 + "gzip": 133823
30 },
31 "react-dom.production.min.js (UMD_PROD)": {
32 - "size": 100233,
33 - "gzip": 31848
32 + "size": 96544,
33 + "gzip": 31188
34 },
35 "react-dom.development.js (NODE_DEV)": {
36 - "size": 577466,
37 - "gzip": 130187
36 + "size": 570160,
37 + "gzip": 129121
38 },
39 "react-dom.production.min.js (NODE_PROD)": {
40 - "size": 98586,
41 - "gzip": 30972
40 + "size": 94731,
41 + "gzip": 30346
42 },
43 "ReactDOM-dev.js (FB_DEV)": {
44 - "size": 578317,
45 - "gzip": 130605
44 + "size": 571472,
45 + "gzip": 129612
46 },
47 "ReactDOM-prod.js (FB_PROD)": {
48 - "size": 412447,
49 - "gzip": 91219
48 + "size": 405312,
49 + "gzip": 90089
50 },
51 "react-dom-test-utils.development.js (NODE_DEV)": {
52 "size": 37876,
@@ -61,60 +61,60 @@
61 "gzip": 10182
62 },
63 "react-dom-unstable-native-dependencies.development.js (UMD_DEV)": {
64 - "size": 86323,
65 - "gzip": 20929
64 + "size": 66641,
65 + "gzip": 16671
66 },
67 "react-dom-unstable-native-dependencies.production.min.js (UMD_PROD)": {
68 - "size": 14157,
69 - "gzip": 4583
68 + "size": 11349,
69 + "gzip": 3900
70 },
71 "react-dom-unstable-native-dependencies.development.js (NODE_DEV)": {
72 - "size": 81826,
73 - "gzip": 19703
72 + "size": 62184,
73 + "gzip": 15356
74 },
75 "react-dom-unstable-native-dependencies.production.min.js (NODE_PROD)": {
76 - "size": 13707,
77 - "gzip": 4458
76 + "size": 10892,
77 + "gzip": 3771
78 },
79 "ReactDOMUnstableNativeDependencies-dev.js (FB_DEV)": {
80 - "size": 81123,
81 - "gzip": 19537
80 + "size": 61607,
81 + "gzip": 15197
82 },
83 "ReactDOMUnstableNativeDependencies-prod.js (FB_PROD)": {
84 - "size": 65265,
85 - "gzip": 15254
84 + "size": 52139,
85 + "gzip": 12586
86 },
87 "react-dom-server.browser.development.js (UMD_DEV)": {
88 - "size": 107196,
89 - "gzip": 27472
88 + "size": 100894,
89 + "gzip": 26193
90 },
91 "react-dom-server.browser.production.min.js (UMD_PROD)": {
92 - "size": 15632,
93 - "gzip": 6077
92 + "size": 14713,
93 + "gzip": 5827
94 },
95 "react-dom-server.browser.development.js (NODE_DEV)": {
96 - "size": 96125,
97 - "gzip": 24739
96 + "size": 89851,
97 + "gzip": 23452
98 },
99 "react-dom-server.browser.production.min.js (NODE_PROD)": {
100 - "size": 15101,
101 - "gzip": 5920
100 + "size": 14188,
101 + "gzip": 5707
102 },
103 "ReactDOMServer-dev.js (FB_DEV)": {
104 - "size": 95444,
105 - "gzip": 24574
104 + "size": 89268,
105 + "gzip": 23281
106 },
107 "ReactDOMServer-prod.js (FB_PROD)": {
108 - "size": 45835,
109 - "gzip": 12001
108 + "size": 45175,
109 + "gzip": 11989
110 },
111 "react-dom-server.node.development.js (NODE_DEV)": {
112 - "size": 98291,
113 - "gzip": 25249
112 + "size": 92017,
113 + "gzip": 23960
114 },
115 "react-dom-server.node.production.min.js (NODE_PROD)": {
116 - "size": 15925,
117 - "gzip": 6228
116 + "size": 15013,
117 + "gzip": 6016
118 },
119 "react-art.development.js (UMD_DEV)": {
120 "size": 361363,
@@ -141,40 +141,40 @@
141 "gzip": 43024
142 },
143 "ReactNativeRenderer-dev.js (RN_DEV)": {
144 - "size": 268852,
145 - "gzip": 46028
144 + "size": 264248,
145 + "gzip": 45270
146 },
147 "ReactNativeRenderer-prod.js (RN_PROD)": {
148 - "size": 206992,
149 - "gzip": 35199
148 + "size": 202770,
149 + "gzip": 34504
150 },
151 "ReactRTRenderer-dev.js (RN_DEV)": {
152 - "size": 202141,
153 - "gzip": 33933
152 + "size": 195970,
153 + "gzip": 32882
154 },
155 "ReactRTRenderer-prod.js (RN_PROD)": {
156 - "size": 150536,
157 - "gzip": 24872
156 + "size": 143566,
157 + "gzip": 23595
158 },
159 "ReactCSRenderer-dev.js (RN_DEV)": {
160 - "size": 189508,
161 - "gzip": 31550
160 + "size": 189548,
161 + "gzip": 31563
162 },
163 "ReactCSRenderer-prod.js (RN_PROD)": {
164 - "size": 139346,
165 - "gzip": 22600
164 + "size": 139382,
165 + "gzip": 22608
166 },
167 "react-test-renderer.development.js (NODE_DEV)": {
168 - "size": 290743,
169 - "gzip": 60340
168 + "size": 284199,
169 + "gzip": 58944
170 },
171 "react-test-renderer.production.min.js (NODE_PROD)": {
172 - "size": 50251,
173 - "gzip": 15366
172 + "size": 47325,
173 + "gzip": 14489
174 },
175 "ReactTestRenderer-dev.js (FB_DEV)": {
176 - "size": 288988,
177 - "gzip": 60118
176 + "size": 282462,
177 + "gzip": 58722
178 },
179 "react-test-renderer-shallow.development.js (NODE_DEV)": {
180 "size": 10657,