From 58cda9cc7fb79ca9df6746de7f9662bc08dc156a Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 13 Oct 2017 12:29:40 +0200 Subject: initial commit --- src/stores/lib/Reaction.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/stores/lib/Reaction.js (limited to 'src/stores/lib/Reaction.js') diff --git a/src/stores/lib/Reaction.js b/src/stores/lib/Reaction.js new file mode 100644 index 000000000..e9bc26d81 --- /dev/null +++ b/src/stores/lib/Reaction.js @@ -0,0 +1,22 @@ +// @flow +import { autorun } from 'mobx'; + +export default class Reaction { + reaction; + hasBeenStarted; + dispose; + + constructor(reaction) { + this.reaction = reaction; + this.hasBeenStarted = false; + } + + start() { + this.dispose = autorun(() => this.reaction()); + this.hasBeenStarted = true; + } + + stop() { + if (this.hasBeenStarted) this.dispose(); + } +} -- cgit v1.2.3-70-g09d2