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/local';

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
coaction/localLocal creation, lifecycle helpers, signal primitives
coaction/sharedShared-capable creation, JSON protocol, authority/client synchronization
coaction/adapterExternal-store binding and state/patch safety helpers
coactionCompatibility surface spanning local and shared selection

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/local or coaction/shared directly.

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

On this page