|
10 | 10 | import invariant from 'shared/invariant';
|
11 | 11 | import warningWithoutStack from 'shared/warningWithoutStack';
|
12 | 12 |
|
13 |
| -let didWarnForAddedNewProperty = false; |
14 | 13 | const EVENT_POOL_SIZE = 10;
|
15 | 14 |
|
16 |
| -const shouldBeReleasedProperties = [ |
17 |
| - 'dispatchConfig', |
18 |
| - '_targetInst', |
19 |
| - 'nativeEvent', |
20 |
| - 'isDefaultPrevented', |
21 |
| - 'isPropagationStopped', |
22 |
| - '_dispatchListeners', |
23 |
| - '_dispatchInstances', |
24 |
| -]; |
25 |
| - |
26 | 15 | /**
|
27 | 16 | * @interface Event
|
28 | 17 | * @see http://www.w3.org/TR/DOM-Level-3-Events/
|
@@ -81,6 +70,8 @@ function SyntheticEvent(
|
81 | 70 | delete this.nativeEvent;
|
82 | 71 | delete this.preventDefault;
|
83 | 72 | delete this.stopPropagation;
|
| 73 | + delete this.isDefaultPrevented; |
| 74 | + delete this.isPropagationStopped; |
84 | 75 | }
|
85 | 76 |
|
86 | 77 | this.dispatchConfig = dispatchConfig;
|
@@ -188,15 +179,35 @@ Object.assign(SyntheticEvent.prototype, {
|
188 | 179 | this[propName] = null;
|
189 | 180 | }
|
190 | 181 | }
|
191 |
| - for (let i = 0; i < shouldBeReleasedProperties.length; i++) { |
192 |
| - this[shouldBeReleasedProperties[i]] = null; |
193 |
| - } |
| 182 | + this.dispatchConfig = null; |
| 183 | + this._targetInst = null; |
| 184 | + this.nativeEvent = null; |
| 185 | + this.isDefaultPrevented = functionThatReturnsFalse; |
| 186 | + this.isPropagationStopped = functionThatReturnsFalse; |
| 187 | + this._dispatchListeners = null; |
| 188 | + this._dispatchInstances = null; |
194 | 189 | if (__DEV__) {
|
195 | 190 | Object.defineProperty(
|
196 | 191 | this,
|
197 | 192 | 'nativeEvent',
|
198 | 193 | getPooledWarningPropertyDefinition('nativeEvent', null),
|
199 | 194 | );
|
| 195 | + Object.defineProperty( |
| 196 | + this, |
| 197 | + 'isDefaultPrevented', |
| 198 | + getPooledWarningPropertyDefinition( |
| 199 | + 'isDefaultPrevented', |
| 200 | + functionThatReturnsFalse, |
| 201 | + ), |
| 202 | + ); |
| 203 | + Object.defineProperty( |
| 204 | + this, |
| 205 | + 'isPropagationStopped', |
| 206 | + getPooledWarningPropertyDefinition( |
| 207 | + 'isPropagationStopped', |
| 208 | + functionThatReturnsFalse, |
| 209 | + ), |
| 210 | + ); |
200 | 211 | Object.defineProperty(
|
201 | 212 | this,
|
202 | 213 | 'preventDefault',
|
@@ -237,49 +248,6 @@ SyntheticEvent.extend = function(Interface) {
|
237 | 248 | return Class;
|
238 | 249 | };
|
239 | 250 |
|
240 |
| -/** Proxying after everything set on SyntheticEvent |
241 |
| - * to resolve Proxy issue on some WebKit browsers |
242 |
| - * in which some Event properties are set to undefined (GH#10010) |
243 |
| - */ |
244 |
| -if (__DEV__) { |
245 |
| - const isProxySupported = |
246 |
| - typeof Proxy === 'function' && |
247 |
| - // https://github.com/facebook/react/issues/12011 |
248 |
| - !Object.isSealed(new Proxy({}, {})); |
249 |
| - |
250 |
| - if (isProxySupported) { |
251 |
| - /*eslint-disable no-func-assign */ |
252 |
| - SyntheticEvent = new Proxy(SyntheticEvent, { |
253 |
| - construct: function(target, args) { |
254 |
| - return this.apply(target, Object.create(target.prototype), args); |
255 |
| - }, |
256 |
| - apply: function(constructor, that, args) { |
257 |
| - return new Proxy(constructor.apply(that, args), { |
258 |
| - set: function(target, prop, value) { |
259 |
| - if ( |
260 |
| - prop !== 'isPersistent' && |
261 |
| - !target.constructor.Interface.hasOwnProperty(prop) && |
262 |
| - shouldBeReleasedProperties.indexOf(prop) === -1 |
263 |
| - ) { |
264 |
| - warningWithoutStack( |
265 |
| - didWarnForAddedNewProperty || target.isPersistent(), |
266 |
| - "This synthetic event is reused for performance reasons. If you're " + |
267 |
| - "seeing this, you're adding a new property in the synthetic event object. " + |
268 |
| - 'The property is never released. See ' + |
269 |
| - 'https://fb.me/react-event-pooling for more information.', |
270 |
| - ); |
271 |
| - didWarnForAddedNewProperty = true; |
272 |
| - } |
273 |
| - target[prop] = value; |
274 |
| - return true; |
275 |
| - }, |
276 |
| - }); |
277 |
| - }, |
278 |
| - }); |
279 |
| - /*eslint-enable no-func-assign */ |
280 |
| - } |
281 |
| -} |
282 |
| - |
283 | 251 | addEventPoolingTo(SyntheticEvent);
|
284 | 252 |
|
285 | 253 | /**
|
@@ -354,7 +322,7 @@ function releasePooledEvent(event) {
|
354 | 322 | const EventConstructor = this;
|
355 | 323 | invariant(
|
356 | 324 | event instanceof EventConstructor,
|
357 |
| - 'Trying to release an event instance into a pool of a different type.', |
| 325 | + 'Trying to release an event instance into a pool of a different type.', |
358 | 326 | );
|
359 | 327 | event.destructor();
|
360 | 328 | if (EventConstructor.eventPool.length < EVENT_POOL_SIZE) {
|
|
0 commit comments