filter text and attributes mutations which target tot a removed node

This commit is contained in:
Yanzhen Yu
2018-10-23 11:48:48 +08:00
parent 68949a08c3
commit 7b9e57bd6c
4 changed files with 450 additions and 45 deletions

View File

@@ -154,14 +154,20 @@ function initMutationObserver(cb: mutationCallBack): MutationObserver {
});
cb({
texts: texts.map(text => ({
id: mirror.getId(text.node as INode),
value: text.value,
})),
attributes: attributes.map(attribute => ({
id: mirror.getId(attribute.node as INode),
attributes: attribute.attributes,
})),
texts: texts
.map(text => ({
id: mirror.getId(text.node as INode),
value: text.value,
}))
// text mutation without ID means the target node has been removed
.filter(text => text.id),
attributes: attributes
.map(attribute => ({
id: mirror.getId(attribute.node as INode),
attributes: attribute.attributes,
}))
// attribute mutation without ID means the target node has been removed
.filter(attribute => attribute.id),
removes,
adds,
});