Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@stateloom/proxy

Proxy-based mutable state with transparent tracking for StateLoom. Familiar to Valtio and MobX users.

Install

pnpm add @stateloom/core @stateloom/proxy

Quick 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)

Documentation