You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
566 B
JavaScript

"use strict";
// TODO: Move this to a stand-alone package, so that it can be reused elsewhere
if (global.__objectID_map == null) {
// Yes, these are deliberately global - we want to ensure that the same value gets the same assigned ID, regardless of where in the dependency tree this ID is obtained
global.__objectID_map = new WeakMap();
global.__objectID_i = 0;
}
module.exports = function objectID(value) {
if (!global.__objectID_map.has(value)) {
global.__objectID_map.set(value, global.__objectID_i++);
}
return global.__objectID_map.get(value);
};