Skip to content

Latest commit

 

History

History
57 lines (38 loc) · 1.63 KB

File metadata and controls

57 lines (38 loc) · 1.63 KB

coaction


coaction / core-api-notes

Core API Notes

create() Input Shapes

create() accepts either a single store factory or an object of slice factories. The object form becomes ambiguous when every enumerable value is a function, because it can mean either:

  • a plain store object that only exposes methods
  • a slices object where each property is a slice factory

For that reason, use sliceMode: 'single' or sliceMode: 'slices' explicitly for function maps.

Local/Main Stores vs Client Stores

Passing transport creates the main/shared store. Passing clientTransport or worker creates a client mirror of that shared store.

Client stores have two important differences:

  • store methods return promises because execution happens on the main store
  • direct setState() calls are rejected on the client; mutate through a store method instead

getState() Method Binding

Store methods and slice methods are rebound to the latest state object when they are invoked. This makes patterns like the following safe even when the method body relies on this:

const { increment } = store.getState();
increment();

The same rule applies to slices:

const { increment } = store.getState().counter;
increment();

createBinder() Boundaries

createBinder() is intended for whole-store adapters that bridge external state systems such as Redux, Zustand, Jotai, Pinia, MobX, or Valtio.

Binder-backed stores are not compatible with Coaction slices mode. If an external integration should live under a slice key, wrap the entire external store instead of mixing it into a slices object.