UNPKG

@empirica/core

Version:
49 lines (48 loc) 1.1 kB
// src/shared/globals.ts import { BehaviorSubject } from "rxjs"; var Globals = class { constructor(globals) { this.attrs = /* @__PURE__ */ new Map(); this.updates = /* @__PURE__ */ new Map(); this.self = new BehaviorSubject(void 0); globals.subscribe({ next: ({ attribute, done }) => { if (attribute) { let val = void 0; if (attribute.val) { val = JSON.parse(attribute.val); } this.updates.set(attribute.key, val); } if (done) { for (const [key, val] of this.updates) { this.obs(key).next(val); } this.updates.clear(); if (this.self) { this.self.next(this); } } } }); } get(key) { const o = this.attrs.get(key); if (o) { return o.getValue(); } return void 0; } obs(key) { let o = this.attrs.get(key); if (!o) { o = new BehaviorSubject(void 0); this.attrs.set(key, o); } return o; } }; export { Globals }; //# sourceMappingURL=chunk-2TT3WJZY.js.map