forked from KieSun/awesome-frontend-source-interpretation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory leak with renderComponentToString()
This is leaking memory. Move event registration to mount time.
- Loading branch information
Showing
7 changed files
with
159 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright 2013 Facebook, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* @providesModule ReactPutListenerQueue | ||
*/ | ||
|
||
"use strict"; | ||
|
||
var PooledClass = require('PooledClass'); | ||
var ReactEventEmitter = require('ReactEventEmitter'); | ||
|
||
var mixInto = require('mixInto'); | ||
|
||
function ReactPutListenerQueue() { | ||
this.listenersToPut = []; | ||
} | ||
|
||
mixInto(ReactPutListenerQueue, { | ||
enqueuePutListener: function(rootNodeID, propKey, propValue) { | ||
this.listenersToPut.push({ | ||
rootNodeID: rootNodeID, | ||
propKey: propKey, | ||
propValue: propValue | ||
}); | ||
}, | ||
|
||
putListeners: function() { | ||
for (var i = 0; i < this.listenersToPut.length; i++) { | ||
var listenerToPut = this.listenersToPut[i]; | ||
ReactEventEmitter.putListener( | ||
listenerToPut.rootNodeID, | ||
listenerToPut.propKey, | ||
listenerToPut.propValue | ||
); | ||
} | ||
}, | ||
|
||
reset: function() { | ||
this.listenersToPut.length = 0; | ||
}, | ||
|
||
destructor: function() { | ||
this.reset(); | ||
} | ||
}); | ||
|
||
PooledClass.addPoolingTo(ReactPutListenerQueue); | ||
|
||
module.exports = ReactPutListenerQueue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright 2013 Facebook, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* @providesModule putDOMComponentListener | ||
*/ | ||
|
||
"use strict"; | ||
|
||
var ReactEventEmitter = require('ReactEventEmitter'); | ||
var ReactMount = require('ReactMount'); | ||
|
||
var listenTo = ReactEventEmitter.listenTo; | ||
|
||
var ELEMENT_NODE_TYPE = 1; | ||
|
||
function putDOMComponentListener(id, registrationName, listener) { | ||
var container = ReactMount.findReactContainerForID(id); | ||
if (container) { | ||
var doc = container.nodeType === ELEMENT_NODE_TYPE ? | ||
container.ownerDocument : | ||
container; | ||
listenTo(registrationName, doc); | ||
} | ||
|
||
ReactEventEmitter.putListener(id, registrationName, listener); | ||
} | ||
|
||
module.exports = putDOMComponentListener; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters