Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/uppercod/zstate
Minimalist state manager, thought to sustain a state based on a mutable object that scales according to nodes.
https://github.com/uppercod/zstate
state
Last synced: about 4 hours ago
JSON representation
Minimalist state manager, thought to sustain a state based on a mutable object that scales according to nodes.
- Host: GitHub
- URL: https://github.com/uppercod/zstate
- Owner: UpperCod
- Created: 2020-10-26T03:09:17.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-28T00:40:18.000Z (about 4 years ago)
- Last Synced: 2024-10-13T12:54:40.884Z (24 days ago)
- Topics: state
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:
```js
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
```js
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
```js
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
```js
app.state;
```Current state.
### set
```js
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
```js
const off = app.on((state) => {
console.log("update:", state);
});
```It subscribes to state changes.