Proxy-based mutable state with transparent tracking for StateLoom. Familiar to Valtio and MobX users.
pnpm add @stateloom/core @stateloom/proxyimport { 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();| 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 |
Ref<T>, Snapshot<T>
~1.2 KB gzipped (+ core)