serialize newly added nodes and update id node map when childList changed
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { INode } from 'rrweb-snapshot';
|
import { INode, serializeNodeWithId } from 'rrweb-snapshot';
|
||||||
import { mirror, throttle, on } from '../utils';
|
import { mirror, throttle, on } from '../utils';
|
||||||
import {
|
import {
|
||||||
mutationCallBack,
|
mutationCallBack,
|
||||||
@@ -69,8 +69,8 @@ function initMutationObserver(cb: mutationCallBack): MutationObserver {
|
|||||||
parentId: id,
|
parentId: id,
|
||||||
id: mirror.getId(n as INode),
|
id: mirror.getId(n as INode),
|
||||||
});
|
});
|
||||||
|
mirror.removeNodeFromMap(n as INode);
|
||||||
});
|
});
|
||||||
// TODO: init new nodes to be INode
|
|
||||||
addedNodes.forEach(n => {
|
addedNodes.forEach(n => {
|
||||||
adds.push({
|
adds.push({
|
||||||
parentId: id,
|
parentId: id,
|
||||||
@@ -82,6 +82,7 @@ function initMutationObserver(cb: mutationCallBack): MutationObserver {
|
|||||||
: mirror.getId(nextSibling as INode),
|
: mirror.getId(nextSibling as INode),
|
||||||
id: mirror.getId(n as INode),
|
id: mirror.getId(n as INode),
|
||||||
});
|
});
|
||||||
|
serializeNodeWithId(n as INode, document, mirror.map);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,6 +171,7 @@ export type Mirror = {
|
|||||||
map: idNodeMap;
|
map: idNodeMap;
|
||||||
getId: (n: INode) => number;
|
getId: (n: INode) => number;
|
||||||
getNode: (id: number) => INode;
|
getNode: (id: number) => INode;
|
||||||
|
removeNodeFromMap: (n: INode) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type throttleOptions = {
|
export type throttleOptions = {
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ export const mirror: Mirror = {
|
|||||||
getNode(id) {
|
getNode(id) {
|
||||||
return mirror.map[id];
|
return mirror.map[id];
|
||||||
},
|
},
|
||||||
|
removeNodeFromMap(n) {
|
||||||
|
const id = n.__sn && n.__sn.id;
|
||||||
|
delete mirror.map[id];
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// copy from underscore
|
// copy from underscore
|
||||||
|
|||||||
Reference in New Issue
Block a user