@stateloom/proxy
v1.0.0-alpha.0
Published
Proxy-based mutable state with transparent tracking for StateLoom. Familiar to Valtio and MobX users.
Readme
@stateloom/proxy
Proxy-based mutable state with transparent tracking for StateLoom. Familiar to Valtio and MobX users.
Install
pnpm add @stateloom/core @stateloom/proxyQuick Start
import { observable, snapshot, observe } from '@stateloom/proxy';
const state = observable({ count: 0, name: 'Alice' });
const dispose = observe(() => {
console.log('Count:', state.count);
});
// "Count: 0"
state.count++; // "Count: 1"
const snap = snapshot(state); // deeply frozen with structural sharing
dispose();Exports
| Export | Description |
| ---------------------- | ------------------------------------------------- |
| observable(obj) | Create a deeply-proxied mutable state object |
| snapshot(proxy) | Create an immutable, structurally-shared snapshot |
| observe(fn) | Auto-tracking side effect |
| subscribe(proxy, cb) | Subscribe to any mutation (including nested) |
| ref(value) | Opt a value out of proxying |
Types
Ref<T>, Snapshot<T>
Size
~1.2 KB gzipped (+ core)
