Skip to content

Instantly share code, notes, and snippets.

@SPY
Created March 20, 2015 14:01
Show Gist options
  • Save SPY/b07977bc2d53c3980695 to your computer and use it in GitHub Desktop.
Save SPY/b07977bc2d53c3980695 to your computer and use it in GitHub Desktop.
/// <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