Skip to content

Instantly share code, notes, and snippets.

@mweststrate
Created March 30, 2017 06:32
Show Gist options
  • Save mweststrate/0095f81b852bb6f083054cd047f2d046 to your computer and use it in GitHub Desktop.
Save mweststrate/0095f81b852bb6f083054cd047f2d046 to your computer and use it in GitHub Desktop.
tracked-mobx.js
/**
Shitty implementation of tracked compatible local component state library powered by MobX
Demo: https://jsfiddle.net/mweststrate/Ltmhe3rh/
@example
class Example extends Component {
// initialize state.count with a value:
@tracked count = 1000;
updateCount = e => {
// updates state.count via setState()
this.count = e.target.value;
};
render() {
return (
<input
value={this.count} // it's just a value!
onChange={this.updateCount}
/>
);
}
}
*/
import {observable} from 'mobx'
import {observer} from 'mobx-react'
export function tracked(target, prop, descriptor) {
observer(target)
return observable(target, prop, descriptor)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment