@gluonjs/store


@gluonjs/store / packages/store/src / StorePluginContext

Interface: StorePluginContext

Properties

definition

readonly definition: StorePluginDefinition


manager

readonly manager: StoreManager


store

readonly store: StorePluginStore

Example

Inspect the manager, definition, and live Store instance supplied when a Store plugin is installed:

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();