add a has method to mirror for checking whether an id is in the map

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent 6ce32f7994
commit 609f51a26a
2 changed files with 6 additions and 2 deletions

View File

@@ -209,8 +209,9 @@ export type inputCallback = (v: inputValue & { id: number }) => void;
export type Mirror = {
map: idNodeMap;
getId: (n: INode) => number;
getNode: (id: number) => INode;
getNode: (id: number) => INode | null;
removeNodeFromMap: (n: INode) => void;
has: (id: number) => boolean;
};
export type throttleOptions = {

View File

@@ -21,7 +21,7 @@ export const mirror: Mirror = {
return n.__sn && n.__sn.id;
},
getNode(id) {
return mirror.map[id];
return mirror.map[id] || null;
},
// TODO: use a weakmap to get rid of manually memory management
removeNodeFromMap(n) {
@@ -33,6 +33,9 @@ export const mirror: Mirror = {
);
}
},
has(id) {
return mirror.map.hasOwnProperty(id);
},
};
// copy from underscore and modified