UNPKG

vuse-rx

Version:

First-class rxjs support for Vue 3

32 lines 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.syncRef = void 0; const vue_1 = require("vue"); function syncRef(ref1, maps, _ref2) { const ref2 = (0, vue_1.ref)(_ref2 == null ? maps.to ? maps.to(ref1.value) : ref1.value : _ref2); for (const key in maps) (ref2[key] = bind(ref1, ref2, maps, key, this)).bind(); return ref2; } exports.syncRef = syncRef; syncRef.with = (...options) => { const opts = Object.assign({}, ...options); const f = syncRef.bind(opts); f.with = syncRef.with.bind(opts); return f; }; const bind = (refBase, refDest, maps, dir, options) => ({ bind: (bindOptions) => { const { ref, map, watch: opts } = Object.assign({ ref: refBase, map: maps[dir], watch: options }, bindOptions); refDest[dir].stop(); refDest[dir].stop = dir === 'to' ? (0, vue_1.watch)(ref, v => refDest.value = map(v), Object.assign({}, options, opts)) : (0, vue_1.watch)(refDest, v => ref.value = map(v), Object.assign({}, options, opts)); }, stop: () => { } }); //# sourceMappingURL=sync-ref.js.map