Last active
March 12, 2017 15:54
-
-
Save fc/712d41682cccdfa559e48b665b6bc781 to your computer and use it in GitHub Desktop.
This file contains 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 characters
// actions.js | |
// @flow | |
export type SetHeightAction = { | |
type: 'box/SET_COLOR', | |
height: number | |
}; | |
export type SetColor = { | |
type: 'box/SET_COLOR', | |
color: string | |
}; | |
export type Action = | |
| SetHeightAction | |
| SetWidthAction; | |
export function setDimensions(height: number, width: number): SetHeightAction { | |
return { | |
type: 'box/SET_DIMENSIONS', | |
height, | |
width | |
}; | |
} | |
export function setWidth(color: string): SetColor { | |
return { | |
type: 'box/SET_COLOR', | |
color | |
}; | |
} | |
// reducers.js | |
// @flow | |
import {initialState} from './data'; | |
import type {State} from './data'; | |
import type {Action} from './actions'; | |
export default function box(state: State = initialState, action: Action): State { | |
switch (action.type) { | |
case 'box/SET_DIMENSIONS': | |
return setDimensions(state, action); | |
case 'box/SET_COLOR': | |
return setColor(state, action); | |
default: | |
return state; | |
} | |
} | |
function setDimensions(state, action) { | |
return { | |
...state, | |
height: action.height, | |
width: action.width | |
}; | |
} | |
function setColor(state, action) { | |
return { | |
...state, | |
color: action.color | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment