Immutable snapshots, natural writes
Write this.user.age += 1 inside set(). Mutative turns the draft into a new frozen snapshot, and untouched branches stay shared.
Components re-render only for the paths they read. Getters cache themselves. Every write becomes a transition you can undo, persist, sync, or hand to a Worker — behind a Zustand-style create().
npm install coaction @coaction/reactWorks withReactVueAngularSvelteSolid
The Coaction octopus with four components on its arms. Each commit re-renders only the components that read the path it changed.
user.name1 rendercart.total1 renderuser.age1 rendercart.items1 renderThe model
Coaction keeps React-style immutable snapshots and adds what they usually lack: fine-grained tracking on reads and reusable transitions on writes.
Write this.user.age += 1 inside set(). Mutative turns the draft into a new frozen snapshot, and untouched branches stay shared.
Reads build a path graph on alien-signals. A reader of user.profile.name ignores a change to age, and your model needs no Signal<T> or Atom<T>.
A plain get total() is a cached computed value. Its dependencies are found automatically, and every reader shares one result.
set() produces the next snapshot and a commit, with patches when a feature needs them. Undo, persistence, sync and workers all build on it.
Live playground
This is the Coaction in this repository, running in your browser. Every cell is a component that counts its own renders: wrapped in observer() on the left, a plain useShop() that subscribes to the whole store on the right.
import { create } from '@coaction/react';
export const useShop = create((set) => ({
user: { name: 'Ada', age: 36 },
cart: { items: [{ name: 'Notebook', price: 12 }] },
theme: 'light',
get total() {
return this.cart.items.reduce((sum, item) => sum + item.price, 0);
},
rename(name: string) {
set(() => {
this.user.name = name;
});
},
birthday() {
set(() => {
this.user.age += 1;
});
},
addItem(item: Item) {
set(() => {
this.cart.items.push(item);
});
},
setTheme(theme: 'light' | 'dark') {
set(() => {
this.theme = theme;
});
}
}));| Component | observer() | plain useShop() |
|---|---|---|
<Avatar />Reads user.name | Ada1 | Ada1 |
<AgeBadge />Reads user.age | 361 | 361 |
<CartTotal />Reads total | $121 | $121 |
<ItemList />Reads cart.items | Notebook1 | Notebook1 |
Numbers count each cell’s renders.
Less glue
A Coaction store reads like a Zustand store. What goes away is the code that only exists to stop extra renders: selectors, shallow equality and hand-written memoization.
import { create, observer } from '@coaction/react';
const useCounter = create((set) => ({
count: 0,
step: 1,
// Cached automatically. Recomputed only when a dependency changes.
get doubled() {
return this.count * 2;
},
increment() {
set(() => {
this.count += this.step; // mutable-looking recipe, immutable next state
});
}
}));
const Counter = observer(() => {
const store = useCounter(); // tracks only the fields this render reads
return (
<button onClick={store.increment}>
{store.count} × 2 = {store.doubled}
</button>
);
});import { create } from 'zustand';
import { useShallow } from 'zustand/react/shallow';
import { useMemo } from 'react';
const useCounter = create((set) => ({
count: 0,
step: 1,
increment: () => set((s) => ({ count: s.count + s.step }))
}));
function Counter() {
const { count, step } = useCounter(
useShallow((s) => ({ count: s.count, step: s.step }))
);
const doubled = useMemo(() => count * 2, [count]);
return (
<button onClick={() => useCounter.getState().increment()}>
{count} × 2 = {doubled}
</button>
);
}Transitions
set() turns a recipe into the next snapshot and a commit. When a feature needs them, the commit carries patches and inverse patches, and undo, persistence, sync and shared runtimes all build on it instead of inventing their own write semantics.
set(() => { this.todos.push(todo) })coactionInvalidates only the readers of what changed.
@coaction/historySteps back and forth with inverse patches.
@coaction/persistSaves commits; late hydration never overwrites new edits.
@coaction/syncA durable outbox, rebased over pulled remote changes.
@coaction/yjsBinds the store to a Yjs document.
coaction/sharedOne authority in a Worker, a mirror in every tab.
Sync backendsFetchCRUDSupabaseFirestoreTanStack QueryIndexedDB
Shared runtime
The same store source moves off the UI thread without a rewrite. A Worker becomes the authority, the page keeps a mirror for reads, and Coaction handles sequencing, patch sync and reconnects.
actionpatches
The worker owns the state. The page proxies actions and mirrors commits.
// worker.ts
import { create } from '@coaction/react/shared';
import { counter } from './counter';
create(counter);
// App.tsx
import { create } from '@coaction/react/shared';
import { counter } from './counter';
const worker = new Worker(new URL('./worker.ts', import.meta.url), {
type: 'module'
});
const useCounter = create(counter, { worker });Honest numbers
Coaction is built for immutable state, cached derived reads and fine-grained invalidation. It does not claim to win every microbenchmark, so here are both sides, measured with the repository’s own benchmarks.
CoactionZustand
84×faster than a selector that recomputes the total on every read
1,000-item cart · ops/sec · higher is better
A hand-maintained total is faster still, because the application does the consistency work itself.
0.55×of Zustand’s selector throughput when every update is followed by a read
1,000-item cart · ops/sec · higher is better
Not drawn: a hand-maintained Zustand total reaches 2,897,112 ops/sec, and replacing large objects drops Coaction to 169, so prefer a focused draft recipe for big collections.
| Case | ops/sec | RME |
|---|---|---|
| Coaction cached accessor getter | 66,109,753 | ±1.67% |
| Coaction computed with manual deps | 33,809,569 | ±1.27% |
| Zustand selector recompute | 787,472 | ±0.13% |
| Zustand maintained total field | 112,062,542 | ±0.25% |
| Case | ops/sec | RME |
|---|---|---|
| Coaction mutable update + cached getter | 48,480 | ±0.81% |
| Coaction mutable update + manual deps | 48,318 | ±0.66% |
| Coaction object replacement + cached getter | 169 | ±4.15% |
| Zustand immutable update + selector recompute | 88,113 | ±0.48% |
| Zustand immutable update + maintained total | 2,897,112 | ±0.53% |
Apple M1 Max, Node 24.16.0, runtime 12ae616, measured 2026-09-11. Single-machine numbers, not release floors; no React rendering is timed. Methodology Performance guide
Ecosystem
The core is framework-agnostic. Bindings cover five frameworks, and whole-store adapters let Zustand, MobX, Redux Toolkit, Pinia, Jotai, Valtio and XState stores join the same model.
Support boundaries are documented, not implied: slices are core-only, and adapters bind a whole store. Support matrix
Fit
Getters, this and automatic tracking are not new: MobX has shipped them for a decade. What is uncommon is having them on an immutable substrate, behind a Zustand-style create(), across five frameworks.
| Coaction | Zustand | MobX | |
|---|---|---|---|
| Model | Immutable reactive state | Minimal external store | Mutable observable graph |
| Render tracking without selectors | observer(), or selectors | Selectors + useShallow | observer() |
| get value() and this | Yes | No | Yes |
| Memoized derived values | Across independent reads | useMemo or reselect | While observed, by default |
| Frozen snapshots, structural sharing | Yes | Via Immer or Mutative | Mutable observables |
| Transition and patch substrate | Core capability | Not core | mobx-state-tree |
| Worker or SharedWorker authority | Built-in shared runtime | Application concern | Application concern |
| Local-first sync | @coaction/sync | External | Library-dependent |
| Runtime cost | Pays for immutable transitions | Very small | Tuned for observable mutation |
Begin with one store and observer(). Add history, persistence, sync or a Worker when the application asks for them, without rewriting the model.
npm install coaction @coaction/react