UNPKG

@joshuafcole/fluorine

Version:

A highly reactive, optionally compiled, and strongly typed view layer for TypeScript.

49 lines 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function shallow_copy(x) { if (x instanceof Array) return [...x]; else if (typeof x === "object") return Object.assign({}, x); else return x; } function stasis(state, on_change) { let current_tx; let log = []; // let observer = (changes: ObservableSlim.Change<T>[]) => { // current_tx.changes.push( // ...changes.map(change => ({ // ...change, // previousValue: shallow_copy(change.previousValue) // })) // ); // }; // let proxy = ObservableSlim.create(state, false, observer); let mutate = function (mutator, no_log = false) { current_tx = { source: mutator.name, changes: [] }; mutator(state); // proxy if (!no_log) log.push(current_tx); if (on_change) on_change(current_tx); }; mutate.objs = function (objs, mutator, no_log = false) { current_tx = { source: mutator.name, changes: [] }; let proxies = objs.map(obj => // ObservableSlim.create(obj, false, observer) obj); mutator(...proxies); if (!no_log) log.push(current_tx); if (on_change) on_change(current_tx); }; return { state: state, log, mutate }; } exports.stasis = stasis; //# sourceMappingURL=stasis.js.map