avocado-old/packages/net/s13n/registry.js
2019-09-22 18:45:33 -05:00

22 lines
626 B
JavaScript

let synchronizedId = 0;
const synchronizedToIdMap = new Map();
const idToSynchronizedMap = new Map();
export function allSynchronizeds() {
return Array.from(idToSynchronizedMap.values());
}
export function idFromSynchronized(Synchronized) {
return synchronizedToIdMap.get(Synchronized);
}
export function synchronizedFromId(id) {
return idToSynchronizedMap.get(id);
}
export function registerSynchronized(Synchronized) {
if (synchronizedToIdMap.has(Synchronized)) {
return;
}
const id = synchronizedId++;
synchronizedToIdMap.set(Synchronized, id);
idToSynchronizedMap.set(id, Synchronized);
return id;
}