UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

28 lines (27 loc) 864 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ValueSyncStore = exports.FanoutSyncStore = void 0; const fanout_1 = require("thingies/lib/fanout"); class FanoutSyncStore { constructor(getSnapshot) { this.getSnapshot = getSnapshot; this.fanout = new fanout_1.FanOut(); this.subscribe = (cb) => this.fanout.listen(cb); } } exports.FanoutSyncStore = FanoutSyncStore; class ValueSyncStore { constructor(value) { this.value = value; this.fanout = new fanout_1.FanOut(); this.subscribe = (cb) => this.fanout.listen(cb); this.getSnapshot = () => this.value; } next(value, force = false) { if (!force && this.value === value) return; this.value = value; this.fanout.emit(); } } exports.ValueSyncStore = ValueSyncStore;