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.
$ npm install mobx-suspend --save
or if using yarn
$ yarn add mobx-suspend
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();
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"
MIT