sipp11
7 years ago
8 changed files with 96 additions and 9 deletions
@ -0,0 +1,10 @@
|
||||
import * as types from '../constants/ActionTypes' |
||||
|
||||
export const incFirstCounter = _ => ({ |
||||
type: types.FIRST_INCREMENT_COUNTER, |
||||
}) |
||||
|
||||
export const assignFirstId = objId => ({ |
||||
type: types.FIRST_ASSIGN_ID, |
||||
newId: objId |
||||
}) |
@ -0,0 +1,3 @@
|
||||
|
||||
export const FIRST_INCREMENT_COUNTER = 'FIRST_INCREMENT_COUNTER' |
||||
export const FIRST_ASSIGN_ID = 'FIRST_ASSIGN_ID' |
@ -1,13 +1,25 @@
|
||||
import React from 'react' |
||||
import { connect } from 'react-redux' |
||||
import { Link } from 'react-router-dom' |
||||
|
||||
const Main = () => ( |
||||
import { getCounter } from '../reducers/first' |
||||
import { incFirstCounter } from '../actions' |
||||
|
||||
const Main = (props) => ( |
||||
<div> |
||||
Main |
||||
|
||||
<Link to={`/roster/12`}>12</Link> |
||||
<p>Counter: { props.counter }</p> |
||||
<p><button onClick={() => props.incFirstCounter() }>Increment</button></p> |
||||
</div> |
||||
) |
||||
|
||||
|
||||
export default Main |
||||
const mapStateToProps = state => ({ |
||||
counter: getCounter(state.first) |
||||
}) |
||||
export default connect( |
||||
mapStateToProps, |
||||
{ incFirstCounter } |
||||
)(Main) |
@ -0,0 +1,34 @@
|
||||
import { |
||||
FIRST_INCREMENT_COUNTER, FIRST_ASSIGN_ID |
||||
} from '../constants/ActionTypes' |
||||
|
||||
const initialState = { |
||||
counter: 1, |
||||
id: {} |
||||
} |
||||
|
||||
const first = (state = initialState, action) => { |
||||
switch (action.type) { |
||||
case FIRST_INCREMENT_COUNTER: |
||||
return { |
||||
...state, |
||||
counter: state.counter +1 |
||||
} |
||||
case FIRST_ASSIGN_ID: |
||||
return { |
||||
...state, |
||||
id: action.newId |
||||
} |
||||
default: |
||||
return { |
||||
counter: 1, |
||||
id: {} |
||||
} |
||||
} |
||||
} |
||||
|
||||
export default first |
||||
|
||||
|
||||
export const getCounter = state => state.counter |
||||
export const getId = state => state.id |
Loading…
Reference in new issue