Primitive to simplify the creation of global stores and the ability to access and mutate them.
| Stage | Category | Version | Last Updated | Demo |
|---|---|---|---|---|
| 3 | Utilities | 1.0.0-next.2 (next) | Aug 13, 2026 | Demo → |
npm i @solid-primitives/flux-store@nextA library for creating Solid stores that enforce a one-way data flow through explicit getters for reads and actions for writes.
createFluxStore— Creates a store instance with explicit getters and actions.createFluxStoreFactory— Creates aFluxStoreencapsulated in a factory function for reusable store instances.createActions— Wraps a record of functions so each runs untracked.createAction— Wraps a single function so it runs untracked.
createFluxStore
Creates a FluxStore — a Solid store that separates reads (getters) from writes (actions).
How to use it
createFluxStore takes two arguments:
initialState— the initial state object.createMethods— object with optionalgettersand requiredactionsfactory functions.getters(state)— return a record of functions that read from the reactive store proxy.actions(setState, state)— return a record of mutation functions.setStateuses draft-first mutations: pass a function that mutates the draft object directly.
import { createFluxStore } from "@solid-primitives/flux-store";
const counterStore = createFluxStore( { value: 5 }, { getters: state => ({ count: () => state.value, isNegative: () => state.value < 0, }), actions: setState => ({ increment(by = 1) { setState(s => { s.value += by; }); }, reset() { setState(s => { s.value = 0; }); }, }), },);
counterStore.getters.count(); // => 5counterStore.actions.increment();counterStore.getters.count(); // => 6counterStore.actions.reset();counterStore.getters.count(); // => 0createFluxStoreFactory
Creates a reusable factory function that produces independent FluxStore instances from the same schema, with an optional initial-state override per instance.
How to use it
import { createFluxStoreFactory } from "@solid-primitives/flux-store";
const createToggleStore = createFluxStoreFactory( { value: false }, { getters: state => ({ isOn: () => state.value, }), actions: setState => ({ toggle() { setState(s => { s.value = !s.value; }); }, }), },);
// Each call creates an isolated store instanceconst toggleA = createToggleStore({ value: true });const toggleB = createToggleStore();
toggleA.getters.isOn(); // => truetoggleB.getters.isOn(); // => false
toggleA.actions.toggle();toggleA.getters.isOn(); // => falsetoggleB.getters.isOn(); // => false (unaffected)The factory accepts an optional override as a plain object or a function:
const store1 = createToggleStore({ value: true });const store2 = createToggleStore(defaults => ({ ...defaults, value: true }));createActions
Wraps each function in a record with createAction and returns a new object of the same shape. Useful for applying the untracked wrapper to a batch of functions at once.
import { createActions } from "@solid-primitives/flux-store";
const actions = createActions({ increment: () => setCount(c => c + 1), reset: () => setCount(0),});createAction
Wraps a single function so its body runs inside untrack — reactive reads inside will not register dependencies and writes will not throw inside owned scopes.
import { createAction } from "@solid-primitives/flux-store";
const increment = createAction(() => setCount(c => c + 1));Changelog
See CHANGELOG.md