UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

33 lines 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NodeEvents = void 0; const fanout_1 = require("./fanout"); class NodeEvents { constructor(api) { this.api = api; // ---------------------------------------------------------------- SyncStore // TODO: .subscribe should use targeted changes check. this.subscribe = (callback) => this.onViewChanges.listen(() => callback()); this.getSnapshot = () => this.api.view(); this.onChanges = new fanout_1.MapFanOut(this.api.api.onChanges, this.getSnapshot); this.onViewChanges = new fanout_1.OnNewFanOut(this.onChanges, this.api.view()); } onChange(listener) { const unsubscribe = this.api.api.onChange.listen((event) => { listener(event); }); return unsubscribe; } /** * Called when this node is deleted. * * @internal * @ignore */ handleDelete() { this.onViewChanges.clear(); this.onChanges.clear(); } } exports.NodeEvents = NodeEvents; //# sourceMappingURL=NodeEvents.js.map