Giter Site home page Giter Site logo

koxr's Introduction

koxr

react兼容ie8状态管理库

INSTALL

npm install koxr

API

observable

参数为非数组, 普通observable变量;

const observableValue = observable(0);

定义一个初始值为0的observable变量

observableValue(1);

observableValue set操作, 异步更新该变量的观察者, 前后两次set同一个值不会更新

observableValue();

observableValue get操作

参数为数组, 在普通observable变量上扩展['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift']等方法;

const observableArray = observable([]);
observableArray.push(0);
observableArray.push(1);
observableArray(); //[0, 1]

autorun

const destory = autorun(() => {
    console.log(observableValue())
});

observableValue� 进行set操作, 都会触发log方法, 执行destory方法终止观察,一般处理副作用

computed

const computedValue = computed(() => {
    return observableValue�() + 1;
})

observableValue� 进行set, ��会重新计算computedValue的值并缓存, computedValue get操作不会重新计算, 一般用作计算响应值

when

const destory = when(() => {
    //
}, () => {
    console.log(observableValue�());
})

observableValue� �set操作, 会计算参数一的值为true时,执行参数二方法; destory执行终止观察

observer

class App extends Component {
    render() {
        return <div>{observableValue()}</div>;
    }
}
export default observer(App);

参数为class

observer(() => {
    return <div>{observableValue()}</div>;
});

参数为function

observableValue set操作自动更新组件

koxr's People

Contributors

baiwenbao avatar

Stargazers

 avatar

Watchers

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