1 | # jetstate
|
2 |
|
3 | [![NPM](https://nodei.co/npm/jetstate.png)](https://nodei.co/npm/jetstate/)
|
4 |
|
5 | [![install size](https://packagephobia.now.sh/badge?p=jetstate)](https://packagephobia.now.sh/result?p=jetstate) [![dependencies](https://david-dm.org/uxitten/jetstate.svg)](https://david-dm.org/uxitten/jetstate.svg)
|
6 |
|
7 |
|
8 | <a href="https://www.npmjs.com/package/jetstate">
|
9 | <img src="https://img.shields.io/npm/v/jetstate.svg" alt="Version">
|
10 | </a>
|
11 |
|
12 | <a href="https://www.npmjs.com/package/jetstate">
|
13 | <img src="https://img.shields.io/npm/l/jetstate.svg" alt="License">
|
14 | </a>
|
15 |
|
16 | <a href="https://www.npmjs.com/package/jetstate">
|
17 | <img src="https://img.shields.io/npm/dm/jetstate.svg" alt="Downloads">
|
18 | </a>
|
19 |
|
20 | state managment
|
21 |
|
22 | ## install
|
23 | ```npm
|
24 | npm i jetstate --save
|
25 | ```
|
26 |
|
27 | ## use
|
28 | ```javascript
|
29 | import { init, state } from 'jetstate';
|
30 |
|
31 | /**
|
32 | * initial new state
|
33 | */
|
34 | init({
|
35 | name: 'time',
|
36 | defaultValue: new Date().getTime(),
|
37 | willUpdate: (previousValue, nextValue) => {
|
38 | console.log('willUpdate', previousValue, nextValue);
|
39 | },
|
40 | shouldUpdate: (previousValue, nextValue) => {
|
41 | if (typeof nextValue 'number') return true;
|
42 | else return false
|
43 | },
|
44 | didUpdate: value => {
|
45 | console.log('didUpdate', value);
|
46 | }
|
47 | });
|
48 |
|
49 | var time = state.time;
|
50 |
|
51 | //with this code, willUpdate is run and then didUpdate is run
|
52 | state.time = new Date().getTime();
|
53 | ``` |
\ | No newline at end of file |