0.0.2-a • Published 2 years ago

anystate v0.0.2-a

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

anyState

What is anyState?

  • Just an object
  • Can must be update via setter
  • Watch state changed
  • Independent any frontend frameworks

Roadmap

  1. Initialize anyState
  2. Simple state
  3. getItem/setItem
  4. Watch onChange
  5. Watch onChange with deep option (inspire by vue)

...

Usage

Initialize anyState object with createStore()

  const anyState =  createStore({
    name: 'John',
    age: 30,
    children: [{
      name: 'Bob',
      age: 5,
    }]
  });

Set state

  anyState.setState({
    name: 'John',
    age: 32,
    children: [{
      name: 'Bob',
      age: 4,
    }]
  });

Get state

  const state = anyState.getState();

Set item

  // const path = 'name';
  const path = 'children[0].name'; // the path to the item
  anyState.setItem(path, 'Jane');

Get item

  const path = 'children[0]';
  const child = anyState.getItem(path);

Watch onChange

  const path = 'name'; // path to item
  anyState.watch(path, (nextState, prevState) => {
     // do anything
  });

Development

install dependencies:

  npm install

run tests:

  npm test

dev:

  npm run dev

Examples

React Todo

Solid Todo

License

MIT

0.0.2-a

2 years ago

0.0.1-d

2 years ago

0.0.1-c

2 years ago

0.0.1-b

2 years ago

0.0.1-a

2 years ago

0.0.1

2 years ago