UNPKG

@signaldb/core

Version:

SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON in

27 lines (26 loc) 725 B
"use strict"; function createSignal(reactivityAdapter, initialValue, isEqual = Object.is) { let value = initialValue; const dependency = reactivityAdapter == null ? void 0 : reactivityAdapter.create(); const isInReactiveScope = () => { if (!(reactivityAdapter == null ? void 0 : reactivityAdapter.isInScope)) return true; return reactivityAdapter.isInScope(); }; const signal = { get() { if (dependency && isInReactiveScope()) dependency.depend(); return value; }, set(newValue) { if (isEqual(value, newValue)) return; value = newValue; if (dependency) dependency.notify(); } }; return signal; } module.exports = createSignal;