UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

25 lines (24 loc) 620 B
import { FanOut } from 'thingies/lib/fanout'; export class FanoutSyncStore { getSnapshot; fanout = new FanOut(); subscribe = (cb) => this.fanout.listen(cb); constructor(getSnapshot) { this.getSnapshot = getSnapshot; } } export class ValueSyncStore { value; fanout = new FanOut(); subscribe = (cb) => this.fanout.listen(cb); constructor(value) { this.value = value; } getSnapshot = () => this.value; next(value, force = false) { if (!force && this.value === value) return; this.value = value; this.fanout.emit(); } }