Skip to content

@gluonjs/core / packages/store/src / StoreDefinition

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

Type Parameters ​

Id ​

Id extends string

State ​

State extends StateTree

Getters ​

Getters extends StoreGetterTree<State>

Actions ​

Actions extends StoreActionTree

Properties ​

id ​

readonly id: Id


options ​

readonly options: DefineStoreOptions<Id, State, Getters, Actions>

Methods ​

use() ​

use(manager): Store<Id, State, Getters, Actions>

Parameters ​

manager ​

StoreManager

Returns ​

Store<Id, State, Getters, Actions>

Example ​

Keep Store configuration reusable and attach it to the specific application-owned manager that should host its state:

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.