@ainb/store

0.0.104 • Public • Published

store

A state container for JavaScript.

Installation

$ yarn add @ainb/store

Usage

import createStore from '@ainb/store';

const store = createStore({ a: 1, b: 2 });

// set state or getter
store.$set('c', { d: 3 });
store.$get('add', () => store.a + store.b);

// watch change
store.$watch('add', (now, old) => {
    // do something;
});

// get state
console.log(store.c); // { d: 3 }
console.log(store.add); // 3

// update state
store.a = 2;
store.c = { f: 4 };

// wait updated
store.$nextTick(() => {
    console.log(store.c); // { f: 4 }
    console.log(store.add); // 4
});

Api

  • $set(key, value): set state
  • $get(key, handler): create getter
  • $delete(key): delete state
  • $watch(key, handler): watch change
  • $nextTick(callback): wait updated

Readme

Keywords

none

Package Sidebar

Install

npm i @ainb/store

Weekly Downloads

1

Version

0.0.104

License

MIT

Unpacked Size

8.38 kB

Total Files

5

Last publish

Collaborators

  • absock
  • edonet