From 609f51a26a15ab09b70a57c1638e34acb2e41541 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] add a has method to mirror for checking whether an id is in the map --- src/types.ts | 3 ++- src/utils.ts | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/types.ts b/src/types.ts index fe50ed3c..4eeae747 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 = { diff --git a/src/utils.ts b/src/utils.ts index 4ce58911..66e5c85c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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