Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC Remove event pooling #1612

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/browser/eventPlugins/BeforeInputEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ var BeforeInputEventPlugin = {
return;
}

var event = SyntheticInputEvent.getPooled(
var event = new SyntheticInputEvent(
eventTypes.beforeInput,
topLevelTargetID,
nativeEvent
Expand Down
4 changes: 2 additions & 2 deletions src/browser/eventPlugins/ChangeEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if (ExecutionEnvironment.canUseDOM) {
}

function manualDispatchChangeEvent(nativeEvent) {
var event = SyntheticEvent.getPooled(
var event = new SyntheticEvent(
eventTypes.change,
activeElementID,
nativeEvent
Expand Down Expand Up @@ -363,7 +363,7 @@ var ChangeEventPlugin = {
topLevelTargetID
);
if (targetID) {
var event = SyntheticEvent.getPooled(
var event = new SyntheticEvent(
eventTypes.change,
targetID,
nativeEvent
Expand Down
2 changes: 1 addition & 1 deletion src/browser/eventPlugins/CompositionEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ var CompositionEventPlugin = {
}

if (eventType) {
var event = SyntheticCompositionEvent.getPooled(
var event = new SyntheticCompositionEvent(
eventType,
topLevelTargetID,
nativeEvent
Expand Down
4 changes: 2 additions & 2 deletions src/browser/eventPlugins/EnterLeaveEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var EnterLeaveEventPlugin = {
var fromID = from ? ReactMount.getID(from) : '';
var toID = to ? ReactMount.getID(to) : '';

var leave = SyntheticMouseEvent.getPooled(
var leave = new SyntheticMouseEvent(
eventTypes.mouseLeave,
fromID,
nativeEvent
Expand All @@ -123,7 +123,7 @@ var EnterLeaveEventPlugin = {
leave.target = from;
leave.relatedTarget = to;

var enter = SyntheticMouseEvent.getPooled(
var enter = new SyntheticMouseEvent(
eventTypes.mouseEnter,
toID,
nativeEvent
Expand Down
18 changes: 6 additions & 12 deletions src/browser/eventPlugins/ResponderEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,44 +169,38 @@ function setResponderAndExtractTransfer(
eventTypes.scrollShouldSetResponder;

var bubbleShouldSetFrom = responderID || topLevelTargetID;
var shouldSetEvent = SyntheticEvent.getPooled(
var shouldSetEvent = new SyntheticEvent(
shouldSetEventType,
bubbleShouldSetFrom,
nativeEvent
);
EventPropagators.accumulateTwoPhaseDispatches(shouldSetEvent);
var wantsResponderID = executeDispatchesInOrderStopAtTrue(shouldSetEvent);
if (!shouldSetEvent.isPersistent()) {
shouldSetEvent.constructor.release(shouldSetEvent);
}

if (!wantsResponderID || wantsResponderID === responderID) {
return null;
}
var extracted;
var grantEvent = SyntheticEvent.getPooled(
var grantEvent = new SyntheticEvent(
eventTypes.responderGrant,
wantsResponderID,
nativeEvent
);

EventPropagators.accumulateDirectDispatches(grantEvent);
if (responderID) {
var terminationRequestEvent = SyntheticEvent.getPooled(
var terminationRequestEvent = new SyntheticEvent(
eventTypes.responderTerminationRequest,
responderID,
nativeEvent
);
EventPropagators.accumulateDirectDispatches(terminationRequestEvent);
var shouldSwitch = !hasDispatches(terminationRequestEvent) ||
executeDirectDispatch(terminationRequestEvent);
if (!terminationRequestEvent.isPersistent()) {
terminationRequestEvent.constructor.release(terminationRequestEvent);
}

if (shouldSwitch) {
var terminateType = eventTypes.responderTerminate;
var terminateEvent = SyntheticEvent.getPooled(
var terminateEvent = new SyntheticEvent(
terminateType,
responderID,
nativeEvent
Expand All @@ -215,7 +209,7 @@ function setResponderAndExtractTransfer(
extracted = accumulate(extracted, [grantEvent, terminateEvent]);
responderID = wantsResponderID;
} else {
var rejectEvent = SyntheticEvent.getPooled(
var rejectEvent = new SyntheticEvent(
eventTypes.responderReject,
wantsResponderID,
nativeEvent
Expand Down Expand Up @@ -297,7 +291,7 @@ var ResponderEventPlugin = {
isEndish(topLevelType) ? eventTypes.responderRelease :
isStartish(topLevelType) ? eventTypes.responderStart : null;
if (type) {
var gesture = SyntheticEvent.getPooled(
var gesture = new SyntheticEvent(
type,
responderID || '',
nativeEvent
Expand Down
2 changes: 1 addition & 1 deletion src/browser/eventPlugins/SelectEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function constructSelectEvent(nativeEvent) {
if (!lastSelection || !shallowEqual(lastSelection, currentSelection)) {
lastSelection = currentSelection;

var syntheticEvent = SyntheticEvent.getPooled(
var syntheticEvent = new SyntheticEvent(
eventTypes.select,
activeElementID,
nativeEvent
Expand Down
3 changes: 1 addition & 2 deletions src/browser/eventPlugins/SimpleEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ var SimpleEventPlugin = {
'SimpleEventPlugin: Unhandled event type, `%s`.',
topLevelType
);
var event = EventConstructor.getPooled(
dispatchConfig,
var event = new EventConstructor(dispatchConfig,
topLevelTargetID,
nativeEvent
);
Expand Down
2 changes: 1 addition & 1 deletion src/browser/eventPlugins/TapEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var TapEventPlugin = {
var event = null;
var distance = getDistance(startCoords, nativeEvent);
if (isEndish(topLevelType) && distance < tapMoveThreshold) {
event = SyntheticUIEvent.getPooled(
event = new SyntheticUIEvent(
eventTypes.touchTap,
topLevelTargetID,
nativeEvent
Expand Down
35 changes: 0 additions & 35 deletions src/browser/syntheticEvents/SyntheticEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

"use strict";

var PooledClass = require('PooledClass');

var emptyFunction = require('emptyFunction');
var getEventTarget = require('getEventTarget');
var merge = require('merge');
Expand Down Expand Up @@ -106,35 +104,6 @@ mergeInto(SyntheticEvent.prototype, {
this.isPropagationStopped = emptyFunction.thatReturnsTrue;
},

/**
* We release all dispatched `SyntheticEvent`s after each event loop, adding
* them back into the pool. This allows a way to hold onto a reference that
* won't be added back into the pool.
*/
persist: function() {
this.isPersistent = emptyFunction.thatReturnsTrue;
},

/**
* Checks if this event should be released back into the pool.
*
* @return {boolean} True if this should not be released, false otherwise.
*/
isPersistent: emptyFunction.thatReturnsFalse,

/**
* `PooledClass` looks for `destructor` on each instance it releases.
*/
destructor: function() {
var Interface = this.constructor.Interface;
for (var propName in Interface) {
this[propName] = null;
}
this.dispatchConfig = null;
this.dispatchMarker = null;
this.nativeEvent = null;
}

});

SyntheticEvent.Interface = EventInterface;
Expand All @@ -155,10 +124,6 @@ SyntheticEvent.augmentClass = function(Class, Interface) {

Class.Interface = merge(Super.Interface, Interface);
Class.augmentClass = Super.augmentClass;

PooledClass.addPoolingTo(Class, PooledClass.threeArgumentPooler);
};

PooledClass.addPoolingTo(SyntheticEvent, PooledClass.threeArgumentPooler);

module.exports = SyntheticEvent;
10 changes: 1 addition & 9 deletions src/browser/syntheticEvents/__tests__/SyntheticEvent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('SyntheticEvent', function() {
SyntheticEvent = require('SyntheticEvent');

createEvent = function(nativeEvent) {
return SyntheticEvent.getPooled({}, '', nativeEvent);
return new SyntheticEvent({}, '', nativeEvent);
};
});

Expand Down Expand Up @@ -70,12 +70,4 @@ describe('SyntheticEvent', function() {
expect(nativeEvent.cancelBubble).toBe(true);
});

it('should be able to `persist`', function() {
var syntheticEvent = createEvent({});

expect(syntheticEvent.isPersistent()).toBe(false);
syntheticEvent.persist();
expect(syntheticEvent.isPersistent()).toBe(true);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('SyntheticWheelEvent', function() {
SyntheticWheelEvent = require('SyntheticWheelEvent');

createEvent = function(nativeEvent) {
return SyntheticWheelEvent.getPooled({}, '', nativeEvent);
return new SyntheticWheelEvent({}, '', nativeEvent);
};
});

Expand Down Expand Up @@ -66,12 +66,4 @@ describe('SyntheticWheelEvent', function() {
expect(syntheticEvent.isPropagationStopped()).toBe(true);
});

it('should be able to `persist`', function() {
var syntheticEvent = createEvent({});

expect(syntheticEvent.isPersistent()).toBe(false);
syntheticEvent.persist();
expect(syntheticEvent.isPersistent()).toBe(true);
});

});
4 changes: 0 additions & 4 deletions src/event/EventPluginHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ var executeDispatchesAndRelease = function(event) {
executeDispatch = PluginModule.executeDispatch;
}
EventPluginUtils.executeDispatchesInOrder(event, executeDispatch);

if (!event.isPersistent()) {
event.constructor.release(event);
}
}
};

Expand Down