weakmap-oid
Generate unique object IDs with WeakMap-based identity set.
Why do I need this?
weakmap-oid
is useful when you need to do shallow (object identity) comparison across objects that were serialized (like in Electron's IPC module) or transformed to another language (like in CefSharp's JavaScript callbacks) or any other cases in which triple-equals (===
) is no longer available. Sending a unique object ID along with the object eliminates the need for deep comparisons on the other side.
weakmap-oid
uses WeakMap
to maintain the mapping between objects and identities. Since native WeakMap
does not prevent garbage collection of its key objects, using weakmap-oid
will not lead to memory leak.
Installation
$ npm install weakmap-oid # or $ yarn add weakmap-oid
Usage
; const oid = ; const a = {};const b = {};const c = b; oidida; // 0oididb; // 1oididc; // 1 oid; // falseoid; // true