@samitouri / QOS-React-2 / commits / 431155d2e2

Revert #1536

It's causing issues in product code. Reverting until it can be investigated further.

Tim Yung committed Jun 14, 2014 at 20:15 UTC 431155d2e231cfb65e236f9289fddf8cea291185
6 files changed +67 -67
src/browser/eventPlugins/DefaultEventPluginOrder.js
+2 -1
@@ -38,7 +38,8 @@ var DefaultEventPluginOrder = [
38 keyOf({SelectEventPlugin: null}),
39 keyOf({CompositionEventPlugin: null}),
40 keyOf({BeforeInputEventPlugin: null}),
41 - keyOf({AnalyticsEventPlugin: null})
41 + keyOf({AnalyticsEventPlugin: null}),
42 + keyOf({MobileSafariClickEventPlugin: null})
43 ];
44
45 module.exports = DefaultEventPluginOrder;
src/browser/eventPlugins/MobileSafariClickEventPlugin.js new
+63
@@ -0,0 +1,63 @@
1 +/**
2 + * Copyright 2013-2014 Facebook, Inc.
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + *
16 + * @providesModule MobileSafariClickEventPlugin
17 + * @typechecks static-only
18 + */
19 +
20 +"use strict";
21 +
22 +var EventConstants = require('EventConstants');
23 +
24 +var emptyFunction = require('emptyFunction');
25 +
26 +var topLevelTypes = EventConstants.topLevelTypes;
27 +
28 +/**
29 + * Mobile Safari does not fire properly bubble click events on non-interactive
30 + * elements, which means delegated click listeners do not fire. The workaround
31 + * for this bug involves attaching an empty click listener on the target node.
32 + *
33 + * This particular plugin works around the bug by attaching an empty click
34 + * listener on `touchstart` (which does fire on every element).
35 + */
36 +var MobileSafariClickEventPlugin = {
37 +
38 + eventTypes: null,
39 +
40 + /**
41 + * @param {string} topLevelType Record from `EventConstants`.
42 + * @param {DOMEventTarget} topLevelTarget The listening component root node.
43 + * @param {string} topLevelTargetID ID of `topLevelTarget`.
44 + * @param {object} nativeEvent Native browser event.
45 + * @return {*} An accumulation of synthetic events.
46 + * @see {EventPluginHub.extractEvents}
47 + */
48 + extractEvents: function(
49 + topLevelType,
50 + topLevelTarget,
51 + topLevelTargetID,
52 + nativeEvent) {
53 + if (topLevelType === topLevelTypes.topTouchStart) {
54 + var target = nativeEvent.target;
55 + if (target && !target.onclick) {
56 + target.onclick = emptyFunction;
57 + }
58 + }
59 + }
60 +
61 +};
62 +
63 +module.exports = MobileSafariClickEventPlugin;
src/browser/eventPlugins/SimpleEventPlugin.js
-23
@@ -19,10 +19,8 @@
19 "use strict";
20
21 var EventConstants = require('EventConstants');
22 -var EventListener = require('EventListener');
22 var EventPluginUtils = require('EventPluginUtils');
23 var EventPropagators = require('EventPropagators');
25 -var ReactMount = require('ReactMount');
24 var SyntheticClipboardEvent = require('SyntheticClipboardEvent');
25 var SyntheticEvent = require('SyntheticEvent');
26 var SyntheticFocusEvent = require('SyntheticFocusEvent');
@@ -33,7 +31,6 @@ var SyntheticTouchEvent = require('SyntheticTouchEvent');
31 var SyntheticUIEvent = require('SyntheticUIEvent');
32 var SyntheticWheelEvent = require('SyntheticWheelEvent');
33
36 -var emptyFunction = require('emptyFunction');
34 var invariant = require('invariant');
35 var keyOf = require('keyOf');
36
@@ -296,9 +293,6 @@ for (var topLevelType in topLevelEventsToDispatchConfig) {
293 topLevelEventsToDispatchConfig[topLevelType].dependencies = [topLevelType];
294 }
295
299 -var ON_CLICK_KEY = keyOf({onClick: null});
300 -var onClickListeners = {};
301 -
296 var SimpleEventPlugin = {
297
298 eventTypes: eventTypes,
@@ -418,23 +412,6 @@ var SimpleEventPlugin = {
412 );
413 EventPropagators.accumulateTwoPhaseDispatches(event);
414 return event;
421 - },
422 -
423 - didPutListener: function(id, registrationName, listener) {
424 - // Mobile Safari does not fire properly bubble click events on
425 - // non-interactive elements, which means delegated click listeners do not
426 - // fire. The workaround for this bug involves attaching an empty click
427 - // listener on the target node.
428 - if (registrationName === ON_CLICK_KEY) {
429 - var node = ReactMount.getNode(id);
430 - onClickListeners[id] = EventListener.listen(node, 'click', emptyFunction);
431 - }
432 - },
433 -
434 - willDeleteListener: function(id, registrationName) {
435 - if (registrationName === ON_CLICK_KEY) {
436 - onClickListeners[id].remove();
437 - }
415 }
416
417 };
src/browser/ui/ReactDefaultInjection.js
+2
@@ -26,6 +26,7 @@ var DefaultEventPluginOrder = require('DefaultEventPluginOrder');
26 var EnterLeaveEventPlugin = require('EnterLeaveEventPlugin');
27 var ExecutionEnvironment = require('ExecutionEnvironment');
28 var HTMLDOMPropertyConfig = require('HTMLDOMPropertyConfig');
29 +var MobileSafariClickEventPlugin = require('MobileSafariClickEventPlugin');
30 var ReactBrowserComponentMixin = require('ReactBrowserComponentMixin');
31 var ReactComponentBrowserEnvironment =
32 require('ReactComponentBrowserEnvironment');
@@ -70,6 +71,7 @@ function inject() {
71 EnterLeaveEventPlugin: EnterLeaveEventPlugin,
72 ChangeEventPlugin: ChangeEventPlugin,
73 CompositionEventPlugin: CompositionEventPlugin,
74 + MobileSafariClickEventPlugin: MobileSafariClickEventPlugin,
75 SelectEventPlugin: SelectEventPlugin,
76 BeforeInputEventPlugin: BeforeInputEventPlugin
77 });
src/browser/ui/__tests__/ReactDOMComponent-test.js
-20
@@ -348,26 +348,6 @@ describe('ReactDOMComponent', function() {
348 'properties to values, not a string.'
349 );
350 });
351 -
352 - it("should execute custom event plugin listening behavior", function() {
353 - var React = require('React');
354 - var SimpleEventPlugin = require('SimpleEventPlugin');
355 -
356 - SimpleEventPlugin.didPutListener = mocks.getMockFunction();
357 - SimpleEventPlugin.willDeleteListener = mocks.getMockFunction();
358 -
359 - var container = document.createElement('div');
360 - React.renderComponent(
361 - <div onClick={() => true} />,
362 - container
363 - );
364 -
365 - expect(SimpleEventPlugin.didPutListener.mock.calls.length).toBe(1);
366 -
367 - React.unmountComponentAtNode(container);
368 -
369 - expect(SimpleEventPlugin.willDeleteListener.mock.calls.length).toBe(1);
370 - });
351 });
352
353 describe('updateComponent', function() {
src/event/EventPluginHub.js
-23
@@ -171,12 +171,6 @@ var EventPluginHub = {
171 var bankForRegistrationName =
172 listenerBank[registrationName] || (listenerBank[registrationName] = {});
173 bankForRegistrationName[id] = listener;
174 -
175 - var PluginModule =
176 - EventPluginRegistry.registrationNameModules[registrationName];
177 - if (PluginModule && PluginModule.didPutListener) {
178 - PluginModule.didPutListener(id, registrationName, listener);
179 - }
174 },
175
176 /**
@@ -196,14 +190,7 @@ var EventPluginHub = {
190 * @param {string} registrationName Name of listener (e.g. `onClick`).
191 */
192 deleteListener: function(id, registrationName) {
199 - var PluginModule =
200 - EventPluginRegistry.registrationNameModules[registrationName];
201 - if (PluginModule && PluginModule.willDeleteListener) {
202 - PluginModule.willDeleteListener(id, registrationName);
203 - }
204 -
193 var bankForRegistrationName = listenerBank[registrationName];
206 - // TODO: This should never be null -- when is it?
194 if (bankForRegistrationName) {
195 delete bankForRegistrationName[id];
196 }
@@ -216,16 +203,6 @@ var EventPluginHub = {
203 */
204 deleteAllListeners: function(id) {
205 for (var registrationName in listenerBank) {
219 - if (!listenerBank[registrationName][id]) {
220 - continue;
221 - }
222 -
223 - var PluginModule =
224 - EventPluginRegistry.registrationNameModules[registrationName];
225 - if (PluginModule && PluginModule.willDeleteListener) {
226 - PluginModule.willDeleteListener(id, registrationName);
227 - }
228 -
206 delete listenerBank[registrationName][id];
207 }
208 },