@sigx/store
v0.4.4
Published
Store framework for SignalX - State management abstraction
Maintainers
Readme
@sigx/store
Store for SignalX — a state management abstraction built on signals. Define stores with reactive state, computed getters, actions, and event-driven mutation tracking.
Install
npm install @sigx/storeUsage
import { component } from 'sigx';
import { defineStore, useStore } from '@sigx/store';
const useCounterStore = defineStore('counter', ({ defineState, defineActions }) => {
const state = defineState({ count: 0 });
const actions = defineActions({
increment() {
state.count++;
},
decrement() {
state.count--;
},
});
return { state, actions };
});
const Counter = component(() => {
const store = useStore(useCounterStore);
return () => (
<div>
<p>Count: {store.state.count}</p>
<button onClick={store.actions.increment}>+</button>
<button onClick={store.actions.decrement}>-</button>
</div>
);
});Key Exports
| Export | Description |
|---|---|
| defineStore(name, setup) | Define a new store with reactive state and actions |
| useStore(store) | Access a store instance within a component |
Setup Context
The setup function receives a context with:
defineState(initial)— Creates reactive state with automatic mutation eventsdefineActions(actions)— Wraps action functions with lifecycle events (onDispatching,onDispatched,onFailure)
Documentation
Full SignalX documentation: signalxjs/docs.
License
MIT © Andreas Ekdahl
