This commit is contained in:
2026-05-25 17:07:28 +08:00
parent 30cba5ee96
commit df501f6151
10000 changed files with 276005 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
// [times, realValue]
const SPLIT = '%';
/** Connect key with `SPLIT` */
export function pathKey(keys) {
return keys.join(SPLIT);
}
class Entity {
instanceId;
constructor(instanceId) {
this.instanceId = instanceId;
}
/** @private Internal cache map. Do not access this directly */
cache = new Map();
get(keys) {
return this.opGet(pathKey(keys));
}
/** A fast get cache with `get` concat. */
opGet(keyPathStr) {
return this.cache.get(keyPathStr) || null;
}
update(keys, valueFn) {
return this.opUpdate(pathKey(keys), valueFn);
}
/** A fast get cache with `get` concat. */
opUpdate(keyPathStr, valueFn) {
const prevValue = this.cache.get(keyPathStr);
const nextValue = valueFn(prevValue);
if (nextValue === null) {
this.cache.delete(keyPathStr);
} else {
this.cache.set(keyPathStr, nextValue);
}
}
}
export default Entity;