-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes unused children components not being disposed - Fixes #13
- Loading branch information
Showing
3 changed files
with
198 additions
and
57 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,43 @@ | ||
'use strict'; | ||
|
||
import { async } from 'metal'; | ||
|
||
class IncrementalDomUnusedComponents { | ||
/** | ||
* Schedules a cleanup of unused components to happen in the next tick. | ||
* @param {!Array<!Component} comps | ||
*/ | ||
static schedule(comps) { | ||
for (var i = 0; i < comps.length; i++) { | ||
comps[i].getRenderer().parent_ = null; | ||
comps_.push(comps[i]); | ||
} | ||
if (!scheduled_) { | ||
scheduled_ = true; | ||
async.nextTick(disposeUnused_); | ||
} | ||
} | ||
} | ||
|
||
var comps_ = []; | ||
var scheduled_ = false; | ||
|
||
/** | ||
* Disposes all sub components that were not rerendered since the last | ||
* time this function was scheduled. | ||
* @protected | ||
*/ | ||
function disposeUnused_() { | ||
for (var i = 0; i < comps_.length; i++) { | ||
if (!comps_[i].isDisposed()) { | ||
var renderer = comps_[i].getRenderer(); | ||
if (!renderer.getParent()) { | ||
renderer.getOwner().disposeSubComponents([comps_[i].config.key]); | ||
} | ||
} | ||
} | ||
scheduled_ = false; | ||
comps_ = []; | ||
} | ||
|
||
export default IncrementalDomUnusedComponents; |
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