|
1 | 1 | import React from 'react'; |
2 | | -import {render} from 'react-dom'; |
3 | | -import Most, {connect} from '../../../lib/react-most' |
| 2 | +import { render } from 'react-dom'; |
| 3 | +import Most, { connect } from '../../../lib/react-most' |
4 | 4 |
|
5 | 5 | const CounterView = props => ( |
6 | | - <div> |
7 | | - <button onClick={props.actions.dec}-</button> |
8 | | - <span>{props.count}</span> |
9 | | - <button onClick={props.actions.inc}>+</button> |
10 | | - </div> |
11 | | - ) |
12 | | - } |
13 | | -}) |
| 6 | + <div> |
| 7 | + <button onClick={props.actions.dec}>-</button> |
| 8 | + <span>{props.count}</span> |
| 9 | + <button onClick={props.actions.inc}>+</button> |
| 10 | + </div> |
| 11 | +) |
14 | 12 |
|
15 | | -CounterView.defaultProps = {count: 0}; |
| 13 | +CounterView.defaultProps = { count: 0 }; |
16 | 14 |
|
17 | | -const reactify = connect((intent$)=>{ |
18 | | - return { |
19 | | - sink$: intent$.map(intent => { |
20 | | - switch(intent.type) { |
21 | | - case 'inc': |
22 | | - return state => ({count: state.count+1}); |
23 | | - case 'dec': |
24 | | - return state => ({count: state.count-1}); |
25 | | - default: |
26 | | - return _ => _; |
27 | | - } |
28 | | - }), |
29 | | - inc: () => ({type: 'inc'}), |
30 | | - dec: () => ({type: 'dec'}), |
31 | | - } |
| 15 | +const reactify = connect((intent$) => { |
| 16 | + return { |
| 17 | + sink$: intent$.map(intent => { |
| 18 | + switch (intent.type) { |
| 19 | + case 'inc': |
| 20 | + return state => ({ count: state.count + 1 }); |
| 21 | + case 'dec': |
| 22 | + return state => ({ count: state.count - 1 }); |
| 23 | + default: |
| 24 | + return _ => _; |
| 25 | + } |
| 26 | + }), |
| 27 | + inc: () => ({ type: 'inc' }), |
| 28 | + dec: () => ({ type: 'dec' }), |
| 29 | + } |
32 | 30 | }) |
33 | 31 |
|
34 | 32 | const Counter = reactify(CounterView) |
35 | 33 |
|
36 | 34 | render( |
37 | | - <Most> |
38 | | - <Counter /> |
39 | | - </Most> |
40 | | - , document.getElementById('app')); |
| 35 | + <Most> |
| 36 | + <Counter /> |
| 37 | + </Most> |
| 38 | + , document.getElementById('app')); |
0 commit comments