Skip to content

Instantly share code, notes, and snippets.

@ItamarShDev
Created August 7, 2018 09:28
Show Gist options
  • Save ItamarShDev/c5b320d2d262bf48558e9544366c1cae to your computer and use it in GitHub Desktop.
Save ItamarShDev/c5b320d2d262bf48558e9544366c1cae to your computer and use it in GitHub Desktop.
The mobx problem example
@inject('appStore') //different store
@observer
class VocalTest extends Component {
constructor(props) {
super(props);
this.hearingTest = new Store(this.props.appStore.devices);
this.prepareTest();
}
playNoise(valueToPlay) {
//play to device
}
/* How can i acheive the following?
* if hasChanged(valueToPlay) {
* playNoise(valueToPlay)
* }
*/
render() {...}
}
import { observable, action } from 'mobx';
class Store {
definition = null;
@observable settings;
@observable device;
//change to objects
@observable loopIndex;
@observable flowIndex;
@observable canPlay;
@observable canMark;
@observable valueToPlay;
/**
* more data
*/
}
@benjamingr
Copy link

autorun(() => {
  playNoise(this.hearingTest.valueToPlay); // reactively call it whenever the valueToPlay changes
});

@ItamarShDev
Copy link
Author

ItamarShDev commented Aug 7, 2018

is this similar to angular's $watch - if yes, bummer @benjamingr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment