Skip to content

@gluonjs/core / packages/store/src / DefineStoreOptions

Interface: DefineStoreOptions<Id, State, Getters, Actions> ​

Type Parameters ​

Id ​

Id extends string

State ​

State extends StateTree

Getters ​

Getters extends StoreGetterTree<State>

Actions ​

Actions extends StoreActionTree

Properties ​

actions? ​

readonly optional actions?: (store) => Actions

Parameters ​

store ​

State & Readonly<Getters>

Returns ​

Actions


getters? ​

readonly optional getters?: (state) => Getters

Parameters ​

state ​

DeepReadonly<State>

Returns ​

Getters


id ​

readonly id: Id


persist? ​

readonly optional persist?: boolean | PersistOptions<State>


state ​

readonly state: () => State

Returns ​

State

Example ​

Describe a Store's stable ID and state factory before turning the options into a reusable definition:

ts
import {
  createStoreManager,
  defineStore,
  type DefineStoreOptions,
  type StoreDefinition,
  type StorePluginContext,
} from '@gluonjs/store';

type CounterState = { count: number };
type Empty = Record<never, never>;
const options = { id: 'counter', state: (): CounterState => ({ count: 0 }) } satisfies DefineStoreOptions<'counter', CounterState, Empty, Empty>;
const counter: StoreDefinition<'counter', CounterState, Empty, Empty> =
  defineStore(options);

const manager = createStoreManager({
  plugins: [(context: StorePluginContext) => {
    console.log(`Mounted ${context.definition.id}`);
  }],
});
const store = counter.use(manager);
store.$patch({ count: 1 });
manager.dispose();

Version-matched documentation. Examples are checked against the public package contracts.