Created
July 28, 2016 02:49
-
-
Save otakustay/d5619cc233c0b76722ac88111a01efe7 to your computer and use it in GitHub Desktop.
Spinner
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
| class Component { | |
| render() { | |
| return this.renderWithTemplate(this.state); | |
| } | |
| initializeEvent(element, name, expession) { | |
| element.addEventListener(name, generateEventHandler(this[name], expression), false) | |
| } | |
| } |
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
| let spinner = new Spinner({value: 1, step: 2}); | |
| spinner.increment(); // Error: Not rendered | |
| spinner.render(); | |
| spinner.increment(); | |
| expect(spinner.state.value).toBe(3): | |
| spinner.increment(); // Not stateless | |
| expect(spinner.state.value).toBe(5): |
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
| class Spinner extends Component { | |
| tempalte = '<input /><span on-click="increment">UP</span><span on-click="decrement">DOWN</span>' | |
| increment() { | |
| this.setState({value: this.state.value + this.state.step}) | |
| } | |
| decrement() { | |
| this.setState({value: this.state.value - this.state.step}) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment