Reference

Core API reference

A curated reference for create options, store methods, types, lifecycle helpers, and isolated entry points.

create(createState, options?)

create() accepts a single store factory/object or a map of slice factories.

const store = create((set, get, store) => ({
  count: 0,
  increment() {
    set(() => {
      this.count += 1;
    });
  }
}));

The factory receives:

  • set: the immutable update boundary;
  • get: current state access or explicit computed declaration;
  • store: the core store shell for advanced integrations.

Store options

OptionPurpose
name?: stringStore name used by diagnostics and integration defaults
middlewares?: Middleware[]Enhancers applied in array order before state materialization
enablePatches?: booleanEnable forward/inverse patch generation locally
sliceMode?: 'auto' | 'single' | 'slices'Resolve the input shape explicitly
transport?: TransportCreate a shared-main authority from an injected transport
transportPolicy?: TransportPolicyRestrict actions, authorize requests, and map public errors

Client options add:

OptionPurpose
worker?: Worker | SharedWorkerBuild a client transport from a worker instance
clientTransport?: TransportInject a client-side transport
executeSyncTimeoutMs?: numberWait before action catch-up falls back to full sync; default 1500

coaction/local intentionally omits all transport-only options.

Store methods and fields

MemberMeaning
nameStore name
sharefalse, 'main', or 'client'
isSliceStoreWhether the input was materialized as slices
getState()Public data, bound methods, and computed getters
getPureState()Data-only representation
getInitialState()State produced during initialization
setState(next)Merge a deep partial or run a draft updater; rejected on clients
subscribe(listener)Subscribe and receive an unsubscribe function
apply(state?, patches?)Low-level integration/transport update; rejected on clients
destroy()Idempotent cleanup of subscriptions, integrations, and transport

Application code should prefer named actions over apply(). apply() is a low-level contract for transports, middleware, and adapters.

Computed declaration

const source = (set, get) => ({
  items: [] as Item[],
  total: get(
    (state) => [state.items] as const,
    (items) => items.reduce((sum, item) => sum + item.price, 0)
  )
});

Call get() with no arguments to read the current root state.

Lifecycle helpers

onStoreReady(store, callback) defers work until state and integrations are fully materialized. The callback may return cleanup that runs during destroy().

wrapStore(store) is available for framework and integration authors that need the callable store shape.

Signal primitives

coaction/local and the compatibility surface re-export advanced alien-signals primitives, including signal, computed, effect, effectScope, batching helpers, and type guards. Application state normally uses getters or get(deps, selector) instead.

Adapter entry

coaction/adapter exposes defineExternalStoreAdapter() (and compatibility alias createBinder()), mutable-adapter snapshot helpers, root replacement helpers, schema errors, and patch path safety utilities. This surface is for integration authors, not ordinary state updates.

For the generated symbol-by-symbol TypeDoc output, see the repository API directory.

On this page