@code-o-mat/globals
Version:
Abstract Package to support CodeOMat series of apps.
48 lines (33 loc) • 864 B
JavaScript
import { NONE, PROPS } from '../constants/values';
import { CACHE } from '../constants/types';
import { assertIsObject } from '../assertions/js-types';
import Meta from '../abstracts/meta';
class Cache extends Meta {
static TYPE = CACHE;
TYPE = CACHE;
constructor(data = {}) {
super();
assertIsObject(data);
this[PROPS] = {...data };
}
clone() {
return new this.constructor({...this[PROPS]});
}
data(data = NONE) {
if (data === NONE) return this[PROPS];
this[PROPS] = data;
return this;
}
get(key, dflt = NONE) {
return ( key in this[PROPS] ) ? this[PROPS][key] : dflt;
}
merge(newData) {
const data = this[PROPS]
this[PROPS] = { ...data, ...newData };
return this;
}
set(key, value) {
this[PROPS] = { ...this[PROPS], [key]: value };
}
}
export default Cache;