UNPKG

@wordpress/format-library

Version:
35 lines (32 loc) 919 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; // Weakly referenced map allows unused ids to be garbage collected. const weakMap = new WeakMap(); // Incrementing zero-based ID value. let id = -1; const prefix = 'link-control-instance'; function getKey(_id) { return `${prefix}-${_id}`; } /** * Builds a unique link control key for the given object reference. * * @param {Object} instance an unique object reference specific to this link control instance. * @return {string | undefined} the unique key to use for this link control. */ function useLinkInstanceKey(instance) { if (!instance) { return; } if (weakMap.has(instance)) { return getKey(weakMap.get(instance)); } id += 1; weakMap.set(instance, id); return getKey(id); } var _default = exports.default = useLinkInstanceKey; //# sourceMappingURL=use-link-instance-key.js.map