Straightforward State
A state object that is conditionally watchable on first depth only.
Install:
npm i -s straigtforward-state
or
yarn add straigtforward-state
import or require
import state from "straightforward-state";
or
const state = require("straightforward-state");
Initialize
state.set = { things: [1,2,3], others: [3,4,5], numberOfThings: 6 };
or
state.set({ things: [1,2,3], numberOfThings: 3 });
Access
Access values as usual
state.things
state.numberOfThings
Set
Set the state properties as usual. When set watchers will be run, mutations does not trigger however, like pushing to an array value.
state.things = [...state.things, 4];
Watch
state.watch.things = (val, was) => {
val
state.things
state.numberOfThings = state.things.length;
};
state.watch.numberOfThings((val, was) => {
val
was
});