0.1.0 • Published 4 years ago

@ainc/store v0.1.0

Weekly downloads
11
License
MIT
Repository
-
Last release
4 years ago

@ainc/store

A tool for create reactive store!

Install

$ yarn add @ainc/store

Usage

import store from '@ainc/store';

// create store
const ob = store({
    a: 1,
    b: 2,
    get c() {
        return this.a + this.b;
    }
});

// get state
console.log(ob.a); // 1
console.log(ob.b); // 2
console.log(ob.b); // 3

// watch change
ob.$watch('a', (val, old) => console.log(val, old));

// subscribe state and change
ob.$subscribe(state => console.log(state));

// subscribe next tick
ob.$nextTick(state => console.log(state));

// change state
ob.a = 3;

// get state
console.log(ob.a); // 3
console.log(ob.b); // 2
console.log(ob.c); // 5

API

store(state: T): Store

create state store;

store.$watch(id: K, handler: (curr: TK, old: TK) => void): () => void;

watch state change by state id, return unwatch handler;

store.$subscribe(handler: (state: Store) => void): () => void;

subscribe state change, return the unsubscribe handler;

store.$nextTick(callback?: (state: Store) => R): Promise<R | void>;

subscribe next tick, return the Promise which update completed;

0.1.0

4 years ago

0.0.115

4 years ago

0.0.114

5 years ago

0.0.113

5 years ago

0.0.112

5 years ago

0.0.111

5 years ago

0.0.110

5 years ago

0.0.109

6 years ago

0.0.108

6 years ago

0.0.107

6 years ago

0.0.106

6 years ago

0.0.105

6 years ago

0.0.104

6 years ago

0.0.103

6 years ago

0.0.102

6 years ago

0.0.101

6 years ago