Coder Social home page Coder Social logo

micro-reaction's Introduction

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.

micro-reaction's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.