Created
March 30, 2017 06:32
-
-
Save mweststrate/0095f81b852bb6f083054cd047f2d046 to your computer and use it in GitHub Desktop.
tracked-mobx.js
This file contains 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
/** | |
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