alcaeus-model
Version:
rdfine models for Alcaeus, Hydra client
32 lines (31 loc) • 1.02 kB
JavaScript
export default class CachedResourceFactoryImpl {
constructor(inner, env) {
this.env = env;
this.__cache = env.termMap();
this.__inner = inner;
}
// get BaseClass() {
// return this.__inner.BaseClass
// }
removeCache(graph) {
this.__cache.delete(graph);
}
clone() {
return new CachedResourceFactoryImpl(this.__inner, this.env);
}
createEntity(pointer, typeAndMixins, options) {
const graph = pointer._context[0].graph || this.env.defaultGraph();
if (!this.__cache.has(graph)) {
this.__cache.set(graph, this.env.termMap());
}
const graphCache = this.__cache.get(graph);
if (!graphCache.has(pointer.term)) {
const resource = this.__inner.createEntity(pointer, typeAndMixins, options);
graphCache.set(pointer.term, resource);
}
return graphCache.get(pointer.term);
}
addMixin(...mixins) {
this.__inner.addMixin(...mixins);
}
}