#745 Remove references to DOM nodes when unmounting
When a null component is passed into m.mount(), remove references to the root DOM element from: - roots - cellCache - nodeCache And remove the associated entries from: - controllers - components
This commit is contained in:
parent
a23a32a3d9
commit
c46567ab81
1 changed files with 16 additions and 4 deletions
20
mithril.js
20
mithril.js
|
|
@ -764,6 +764,8 @@ var m = (function app(window, undefined) {
|
||||||
controllers[index].onunload(event);
|
controllers[index].onunload(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isNullComponent = component === null;
|
||||||
|
|
||||||
if (!isPrevented) {
|
if (!isPrevented) {
|
||||||
m.redraw.strategy("all");
|
m.redraw.strategy("all");
|
||||||
m.startComputation();
|
m.startComputation();
|
||||||
|
|
@ -777,14 +779,24 @@ var m = (function app(window, undefined) {
|
||||||
components[index] = component;
|
components[index] = component;
|
||||||
}
|
}
|
||||||
endFirstComputation();
|
endFirstComputation();
|
||||||
|
if (isNullComponent) {
|
||||||
|
removeRootElement(root, index);
|
||||||
|
}
|
||||||
return controllers[index];
|
return controllers[index];
|
||||||
}
|
}
|
||||||
if (!component) {
|
if (isNullComponent) {
|
||||||
roots.splice(index, 1);
|
removeRootElement(root, index);
|
||||||
controllers.splice(index, 1);
|
|
||||||
components.splice(index, 1);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function removeRootElement(root, index) {
|
||||||
|
roots.splice(index, 1);
|
||||||
|
controllers.splice(index, 1);
|
||||||
|
components.splice(index, 1);
|
||||||
|
reset(root);
|
||||||
|
nodeCache.splice(getCellCacheKey(root), 1);
|
||||||
|
}
|
||||||
|
|
||||||
var redrawing = false, forcing = false;
|
var redrawing = false, forcing = false;
|
||||||
m.redraw = function(force) {
|
m.redraw = function(force) {
|
||||||
if (redrawing) return;
|
if (redrawing) return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue