Skip to content

Instantly share code, notes, and snippets.

@Denommus
Created August 22, 2017 20:11
Show Gist options
  • Save Denommus/59a4d02a395c021b987f37a1b0cefcc0 to your computer and use it in GitHub Desktop.
Save Denommus/59a4d02a395c021b987f37a1b0cefcc0 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import Rx, { Subject, Observable } from 'rxjs';
import { connect, combineProps } from 'rx-react-container';
import logo from './logo.svg';
import './App.css';
class AppComponent extends Component {
render() {
return (
<div>
<button onClick={this.props.onMinus}>-{this.props.step}</button>
[<span>{this.props.totalCount}</span>]
<button onClick={this.props.onPlus}>+{this.props.step}</button>
</div>
);
}
}
function appController(container) {
const onMinus$ = new Subject();
const onPlus$ = new Subject();
const click$ = Observable
.merge(
onMinus$.map(() => -1),
onPlus$.map(() => 1)
);
const step$ = Observable.of(1);
const totalCount$ = click$
.startWith(0)
.scan((acc, x) => acc + x, 0);
return combineProps({ totalCount$, step$ }, { onMinus$, onPlus$ });
}
const App = connect(appController)(AppComponent);
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment