Revisions
-
nicolashery revised this gist
May 16, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -37,9 +37,9 @@ class App extends React.Component { .do(console.log.bind(console, 'requested')) .flatMapLatest(query => api.getData$(query).map(_.identity)) .do(console.log.bind(console, 'updated')) .subscribe(data => this.setState({ loading: false, data: data })); } -
nicolashery revised this gist
May 16, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ let api = { .end((err, resp) => cb(err, resp && resp.body)); }, getData$: Rx.Observable.fromNodeCallback(api.getData.bind(api)) }; class App extends React.Component { @@ -35,7 +35,7 @@ class App extends React.Component { .do(() => this.setState({loading: true})) .throttle(400) .do(console.log.bind(console, 'requested')) .flatMapLatest(query => api.getData$(query).map(_.identity)) .do(console.log.bind(console, 'updated')) .subscribe(response => this.setState({ loading: false, -
nicolashery created this gist
May 16, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,69 @@ import React from 'react'; import _ from 'lodash'; import Rx from 'rx'; import superagent from 'superagent'; let api = { host: 'http//localhost:3001', getData(query, cb) { superagent .get(this.host + '/data') .accept('json') .query(query) .end((err, resp) => cb(err, resp && resp.body)); }, getData: Rx.Observable.fromNodeCallback(api.getData.bind(api)) }; class App extends React.Component { constructor(props) { super(props) this.state = { token: 1, loading: false, data: {} }; } componentWillMount() { this.intent$ = new Rx.Subject(); this.intent$ .do(console.log.bind(console, 'clicked')) .do(() => this.setState({loading: true})) .throttle(400) .do(console.log.bind(console, 'requested')) .flatMapLatest(query => api.getCompanies$(query).map(_.identity)) .do(console.log.bind(console, 'updated')) .subscribe(response => this.setState({ loading: false, responses: this.state.responses.concat(response) })); } componentWillUnmount() { this.intent$.dispose(); } render() { return ( <div> <p>{this.state.loading ? 'loading...' : '.'}</p> <p> <button onClick={this.handleClick.bind(this)}>click me</button> <strong>{` ${this.state.token}`}</strong> </p> <pre>{JSON.stringify(this.state.data)}</pre> </div> ); } handleClick() { this.intent$.onNext({token: this.state.token}); this.setState({token: this.state.token + 1}); } } React.render(<App />, document.getElementById('app'));