Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import Rx, { Subject, Observable } from 'rxjs';
  3. import { connect, combineProps } from 'rx-react-container';
  4. import logo from './logo.svg';
  5. import './App.css';
  6.  
  7. class AppComponent extends Component {
  8. render() {
  9. return (
  10. <div>
  11. <button onClick={this.props.onMinus}>-{this.props.step}</button>
  12. [<span>{this.props.totalCount}</span>]
  13. <button onClick={this.props.onPlus}>+{this.props.step}</button>
  14. </div>
  15. );
  16. }
  17. }
  18.  
  19. function appController(container) {
  20. const onMinus$ = new Subject();
  21. const onPlus$ = new Subject();
  22.  
  23. const click$ = Observable
  24. .merge(
  25. onMinus$.map(() => -1),
  26. onPlus$.map(() => 1)
  27. );
  28. const step$ = Observable.of(1);
  29.  
  30. const totalCount$ = click$
  31. .startWith(0)
  32. .scan((acc, x) => acc + x, 0);
  33.  
  34. return combineProps({ totalCount$, step$ }, { onMinus$, onPlus$ });
  35. }
  36.  
  37. const App = connect(appController)(AppComponent);
  38.  
  39. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement