vuecssuiant-designantdreactantantd-vueenterprisefrontendui-designvue-antdvue-antd-uivue3vuecomponent
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
864 B
29 lines
864 B
export type KeyType = string | number; |
|
type ValueType = [number, any]; // [times, realValue] |
|
const SPLIT = '%'; |
|
class Entity { |
|
instanceId: string; |
|
constructor(instanceId: string) { |
|
this.instanceId = instanceId; |
|
} |
|
/** @private Internal cache map. Do not access this directly */ |
|
cache = new Map<string, ValueType>(); |
|
|
|
get(keys: KeyType[] | string): ValueType | null { |
|
return this.cache.get(Array.isArray(keys) ? keys.join(SPLIT) : keys) || null; |
|
} |
|
|
|
update(keys: KeyType[] | string, valueFn: (origin: ValueType | null) => ValueType | null) { |
|
const path = Array.isArray(keys) ? keys.join(SPLIT) : keys; |
|
const prevValue = this.cache.get(path)!; |
|
const nextValue = valueFn(prevValue); |
|
|
|
if (nextValue === null) { |
|
this.cache.delete(path); |
|
} else { |
|
this.cache.set(path, nextValue); |
|
} |
|
} |
|
} |
|
|
|
export default Entity;
|
|
|