mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Faster Listener Deletion
Whenever a component is unmounted, we delete all listeners that might have been attached. This sucks because most applications, Facebook included, do not use every listener. There's a lot of wasted computation, especially if many components are mounted and unmounted. This changes `deleteAllListeners` to more delete listeners more efficiently.
This commit is contained in:
committed by
Paul O’Shannessy
parent
c692d9e844
commit
510146eb6d
@@ -35,7 +35,7 @@ var CallbackRegistry = {
|
||||
/**
|
||||
* Stores `listener` at `listenerBank[registrationName][id]`. Is idempotent.
|
||||
*
|
||||
* @param {string} id ID of the DOM node.
|
||||
* @param {string} id ID of the DOM element.
|
||||
* @param {string} registrationName Name of listener (e.g. `onClick`).
|
||||
* @param {?function} listener The callback to store.
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ var CallbackRegistry = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {string} id ID of the DOM node.
|
||||
* @param {string} id ID of the DOM element.
|
||||
* @param {string} registrationName Name of listener (e.g. `onClick`).
|
||||
* @return {?function} The stored callback.
|
||||
*/
|
||||
@@ -58,7 +58,7 @@ var CallbackRegistry = {
|
||||
/**
|
||||
* Deletes a listener from the registration bank.
|
||||
*
|
||||
* @param {string} id ID of the DOM node.
|
||||
* @param {string} id ID of the DOM element.
|
||||
* @param {string} registrationName Name of listener (e.g. `onClick`).
|
||||
*/
|
||||
deleteListener: function(id, registrationName) {
|
||||
@@ -68,6 +68,17 @@ var CallbackRegistry = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Deletes all listeners for the DOM element with the supplied ID.
|
||||
*
|
||||
* @param {string} id ID of the DOM element.
|
||||
*/
|
||||
deleteAllListeners: function(id) {
|
||||
for (var registrationName in listenerBank) {
|
||||
delete listenerBank[registrationName][id];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* This is needed for tests only. Do not use!
|
||||
*/
|
||||
|
||||
@@ -112,17 +112,7 @@ var EventPluginHub = {
|
||||
|
||||
deleteListener: CallbackRegistry.deleteListener,
|
||||
|
||||
/**
|
||||
* Deletes all listeners for the DOM element with the supplied ID.
|
||||
*
|
||||
* @param {string} domID ID of a DOM element.
|
||||
*/
|
||||
deleteAllListeners: function(domID) {
|
||||
var registrationNamesKeys = EventPluginRegistry.registrationNamesKeys;
|
||||
for (var ii = 0; ii < registrationNamesKeys.length; ii++) {
|
||||
CallbackRegistry.deleteListener(domID, registrationNamesKeys[ii]);
|
||||
}
|
||||
},
|
||||
deleteAllListeners: CallbackRegistry.deleteAllListeners,
|
||||
|
||||
/**
|
||||
* Allows registered plugins an opportunity to extract events from top-level
|
||||
|
||||
Reference in New Issue
Block a user