UNPKG

json-crdt-repo

Version:

JSON CRDT server and syncing local-first browser client

19 lines (18 loc) 554 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shareByKey = void 0; const rxjs_1 = require("rxjs"); const shareByKey = (sub) => { const map = {}; return (key) => { const observable = map[key]; if (observable) return observable; return (map[key] = (0, rxjs_1.defer)(() => sub(key)).pipe((0, rxjs_1.finalize)(() => { delete map[key]; }), (0, rxjs_1.share)({ resetOnRefCountZero: true, }))); }; }; exports.shareByKey = shareByKey;