Skip to content

simplefeel/micro-reaction

Repository files navigation

micro-reaction

Version Version Twitter: simplefeel Twitter: simplefeel License: MIT

one extremely simple observe state library, it's small, but strong.

Motivation

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.

Relations

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.

Install

npm install --save micro-reaction

Usage

Nested properties

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;

Dynamic properties

import { observable, observe } from "micro-reaction";

const ob = observable();

observe(() => console.log(ob.a));

// logs undefined
// logs 2
ob.a = 2;

Arrays

import { observable, observe } from "micro-reaction";

const ob = observable([]);

observe(() => console.log(ob));

// logs []
// logs [2]
ob.push(2);

API

  • 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.

About

one extremely simple observe state library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published