Last active
December 20, 2017 07:50
-
-
Save vivainio/9d07db5e316d74864ce3935c6710e0a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { autorun } from "mobx"; | |
| export function startObserving(component: any, expression: () => void) { | |
| const disposer = autorun(expression); | |
| if (!component.__mobx_unsubs) { | |
| component.__mobx_unsubs = [disposer]; | |
| } else { | |
| component.__mobx_unsubs.push(disposer); | |
| } | |
| } | |
| export function stopObserving(component: any) { | |
| if (!component.__mobx_unsubs) { | |
| throw new Error( | |
| "Stopped observing without any observers. Did you screw up?" | |
| ); | |
| } | |
| component.__mobx_unsubs.forEach(disposer => disposer()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment