Created
March 20, 2015 14:01
-
-
Save SPY/b07977bc2d53c3980695 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
| /// <reference path="../../defs/_references.d.ts" /> | |
| import {createFactory} from 'react'; | |
| import Rx from 'rx'; | |
| import RxComponent = require('src/utils/RxComponent'); | |
| const div = createFactory('div'); | |
| interface CounterProps { | |
| signal: Rx.Observable<number>; | |
| } | |
| interface CounterState { | |
| times?: number; | |
| } | |
| class CounterClass extends RxComponent<CounterProps, CounterState> { | |
| constructor(props: CounterProps) { | |
| super(props); | |
| this.state = { times: 0 }; | |
| this.subscribe(this.props.signal, this.updateTimes); | |
| } | |
| updateTimes(n: number) { | |
| this.setState({ times: n }); | |
| } | |
| render() { | |
| return div({className: 'Counter'}, this.state.times); | |
| } | |
| } | |
| export = createFactory(CounterClass); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment