1.1.0 • Published 4 years ago

zstate v1.1.0

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

zstate

Minimalist state manager, thought to sustain a state based on a mutable object that scales according to nodes.

Nodes?

The nodes are instances that are associated with the state, these instances allow isolated work, example:

import createState from "zstate";

const stateA = createState();

const stateB = A("b");

stateA.on(() => {
    console.log("update");
});

stateB.set({ name: "Uppercod" });

Del ejemplo podemos destacar :

  1. stateA contiene a stateB.
  2. stateB nunca conoce a stateA.

Install

npm install zstore

Usage

import state from "zstate";

const state = store({
    toggle: false,
});

state.on(() => {
    console.log("update");
});

const toggle = ({ toggle }) => ({ toggle: !toggle });

state.set(toggle); // true
state.set(toggle); // false

Instance

import createState from "zstate";

const app = createState(initialState);

Creates an instance of the state that returns a function that contains the following static properties and methods:

state

app.state;

Current state.

set

app.set({ any: "value" });

Update current state, set does not replace current state, just merge.

If the property to update is defined as null or undefined, example {any: null}, it will be removed from the object. if this property is a node, its effects on the parent will be eliminated.

on

const off = app.on((state) => {
    console.log("update:", state);
});

It subscribes to state changes.

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago