@gluonjs/store / 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
readonlyid:Id
options
readonlyoptions:DefineStoreOptions<Id,State,Getters,Actions>
Methods
use()
use(
manager):Store<Id,State,Getters,Actions>
Parameters
manager
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:
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();