UNPKG

@toolpad/utils

Version:

Shared utilities used by Toolpad packages.

19 lines (18 loc) 345 B
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. */ export function getObjectKey(object) { let id = weakMap.get(object); if (!id) { id = getNextId(); weakMap.set(object, id); } return id; }