@sandstack/neuron
TypeScript icon, indicating that this package has built-in type declarations

0.0.0-beta.0.89 • Public • Published

npm version build npm bundle size

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.

Warning: This library is still experimental and is not ready for production.

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.

/@sandstack/neuron/

    Package Sidebar

    Install

    npm i @sandstack/neuron

    Weekly Downloads

    22

    Version

    0.0.0-beta.0.89

    License

    MIT

    Unpacked Size

    1.07 MB

    Total Files

    80

    Last publish

    Collaborators

    • hjrdave