Core concepts

Store modes and entry points

Understand local stores, shared authorities, client mirrors, and Coaction's isolated package boundaries.

The same public store contract appears in three runtime modes.

Modestore.shareMutation authorityMethod result
LocalfalseCurrent runtimeSynchronous
Shared main'main'Main runtimeSynchronous on the authority
Shared client'client'Main runtimePromise returned to the client

Local mode

import { create } from 'coaction';

const store = create(source);

Local mode owns state and execution in one runtime. It keeps patch generation off unless you explicitly enable it, making it the recommended starting point.

Shared main mode

A store becomes a shared authority when it owns a main transport or runs in the detected worker authority environment:

import { create } from 'coaction/shared';

const store = create(source, { transport });

The main store executes actions, commits state, emits ordered patches, and serves full snapshots.

Shared client mode

Passing a Worker, SharedWorker, or client transport creates a mirror:

const store = create(source, { worker });

await store.getState().increment();

Client methods are async because execution happens on the authority. The client may read and subscribe to mirrored state, but direct setState() and apply() calls are rejected.

Isolated entry points

The package exposes static boundaries so a bundler can avoid loading unrelated runtime code:

EntryContains
coactionLocal creation, lifecycle helpers, signal primitives
coaction/sharedShared-capable creation, the JSON protocol, authority and client mirrors
coaction/adapterExternal-store binding and state/patch safety helpers

Framework packages expose their own create() wrapper and may support both local and worker options. Vanilla code gets the clearest bundle boundary by choosing coaction or coaction/shared directly.

Three things the word "sync" gets used for

They compose, and none of them implies another:

What it is
Reactive trackingWhich components re-render when a field changes — observer, selectors, computed getters.
Shared authorityOne store owns the state; other JavaScript contexts hold mirrors and call actions on it over a transport. This page.
Remote synchronizationA durable outbox, a rebase against a server, offline recovery — @coaction/sync.

A local store can synchronize with a server without ever creating a Worker. And a shared store's mirrors are views of one authority, not replicas that diverge and get merged — which is what the same vocabulary means in most other libraries.

Continue with the shared runtime overview for authority semantics and deployment rules.

On this page