UNPKG

memory-orm

Version:
67 lines (66 loc) 1.68 kB
'use strict' Object.defineProperty(exports, '__esModule', { value: true }) exports.Set = void 0 const mem_1 = require('./mem') class Set { constructor({ $name, all, model }) { this.set = f_common('reset') this.reset = f_common('reset') this.merge = f_common('merge') this.add = f_item(f_common('merge')) this.append = f_item(f_common('merge')) this.reject = f_common('remove') this.del = f_item(f_common('remove')) this.remove = f_item(f_common('remove')) this.updates = f_update this.update = f_item(f_update) this.clear_cache = f_clear this.refresh = f_clear this.rehash = f_clear this.$name = $name this.model = model this.all = all this.finder = all._finder } find(...ids) { const meta = mem_1.State.meta() const journal = mem_1.State.journal(this.$name.list) for (const id of ids) { const o = this.all.$memory[id] if (!o) continue o.meta = meta journal.$memory[id] = o this.clear_cache(true) return o.item } return null } } exports.Set = Set function f_common(type) { return function (list, parent) { const is_hit = this.finder.data_set(type, list, parent) this.clear_cache(is_hit) } } function f_update(list, parent) { if (parent) { const is_hit = this.finder.data_set('update', list, parent) this.clear_cache(is_hit) } } function f_item(cb) { return function (item, parent) { if (item) { cb.call(this, [item], parent) } } } function f_clear(is_hit = true) { if (is_hit) { for (const name of this.$name.depends) { mem_1.State.notify(name) } } } //# sourceMappingURL=set.js.map