@sandstack/neuron
v0.0.0-beta.0.92
Published
Neuron is a lightweight framework agnostic global state manager for Javascript apps, with React support
Downloads
485
Maintainers
Readme
Neuron Global State Manager
The Neuron Global State Manager is a small, bare bones, framework agnostic library for building framework specific global state managers.
Neuron Vanilla can be used in any js application by itself or you can tailor it to your framework of choice. My goal is to create framework specific version of this that use vanilla under the hood. See Neuron React as an example.
Setup Store
Create a new Store
import { createStore } from "@sandstack/neuron";
export const Store = createStore();
Add initial state to Store
Store.add({
key: "name",
state: "Ash Ketchum",
});
Store.add({
key: "age",
state: 10,
});
Update state
Store.set("name", "Gary Oak"); //key, new state
Get state
Store.get("name"); //key
Listen for state changes
Store.onDispatch((dispatchItem) => {
if (dispatchItem.key === "name") {
console.log(dispatchItem.state);
}
});
//initial console.log output
//name: Ash Ketchum
//new console.log output
//name: Gary Oak
Learn more about Vanilla Neuron and Neuron React.