rewrite mutation observer handler with lazy child list calculation

This commit is contained in:
Yanzhen Yu
2018-10-22 23:08:05 +08:00
parent a88a79d821
commit d588f738b8
6 changed files with 112 additions and 36 deletions

View File

@@ -180,6 +180,7 @@ export class Replayer {
mutation.node,
this.iframe.contentDocument!,
mirror.map,
true,
) as Node;
const parent = (mirror.getNode(mutation.parentId) as Node) as Element;
if (mutation.nextId) {
@@ -213,8 +214,13 @@ export class Replayer {
});
d.removes.forEach(mutation => {
const target = (mirror.getNode(mutation.id) as Node) as Element;
const parent = (mirror.getNode(mutation.parentId) as Node) as Element;
parent.removeChild(target);
const parent = (mirror.getNode(
mutation.parentId!,
) as Node) as Element;
// target may be removed with its parents before
if (parent) {
parent.removeChild(target);
}
delete mirror.map[mutation.id];
});
break;