mobx-suspend
mobx utilities to suspend/unsuspend reactions
Last updated a year ago by alonbd .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mobx-suspend 
SYNC missed versions from official npm registry.

mobx-suspend

npm version build status npm downloads

mobx utilities to suspend/unsuspend reactions

mobx-suspend contains functions you can use instead of the standard mobx reaction and computed features that allows them to be suspended dynamically.

Installation

$ npm install mobx-suspend --save

or if using yarn

$ yarn add mobx-suspend

Basic Usage

Suspendable computed

    import {observable,autorun,computed} from 'mobx';
    import {suspendableComputed} from "mobx-suspend";
    
    const myComputed = suspendableComputed();
    
    class MyClass {
        @observable
        value = "initial";
        @myComputed
        get actual(){
         return `${this.value}-with-addition`
        }
    }
    const instance = new MyClass();
    autorun(()=>console.log(instance.value))
    myComputed.suspend();
    instance.value = "first change";
    // console.log is not called
    instance.value = "second change";
    //console.log is not called
    myComputed.unsuspend();

Suspendable reaction

    import {suspendableReaction} from "mobx-suspend";
    import {observable} from "mobx";
    
    const value = observable.box("initial");
    const reaction = suspendableReaction(()=>value.get(),v=>console.log(v))
    reaction.suspend();
    value.set("new value");
    //the console.log action is not called
    reaction.unsuspend()
    //the console.log action is called with "new value"

License

MIT

Current Tags

  • 0.0.2                                ...           latest (a year ago)

2 Versions

  • 0.0.2                                ...           a year ago
  • 0.0.1                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |