one extremely simple observe state library, it's small, but strong.
The project is inspired by observer-util and wana, but they is too large and not cleary read, so I refactor it. to be simple and better learn.
micro-reaction-miniprogram is a simple and strong state manange for miniprogram, it use micro-reaction as the reactivity system which observe state and auto run effect when state change.
npm install --save micro-reaction
import { observable, observe } from "micro-reaction";
const ob = observable({
a: {
b: 1
}
});
observe(() => console.log(ob.a.b));
// logs: 1
// logs: 2
ob.a.b = 2;
import { observable, observe } from "micro-reaction";
const ob = observable();
observe(() => console.log(ob.a));
// logs undefined
// logs 2
ob.a = 2;
import { observable, observe } from "micro-reaction";
const ob = observable([]);
observe(() => console.log(ob));
// logs []
// logs [2]
ob.push(2);
-
observable(object)
create a observable object, return a proxy object with es6 proxy.
-
observe(function)
pass a function ,reaction auto run when it use a observable state.