@toolpad/utils
Version:
Shared utilities used by Toolpad packages.
25 lines (23 loc) • 455 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getObjectKey = getObjectKey;
const weakMap = new WeakMap();
let nextId = 0;
function getNextId() {
const id = `object-id::${nextId}`;
nextId += 1;
return id;
}
/**
* Used to generate ids for object instances.
*/
function getObjectKey(object) {
let id = weakMap.get(object);
if (!id) {
id = getNextId();
weakMap.set(object, id);
}
return id;
}
;