Skip to content

Instantly share code, notes, and snippets.

@fc
Last active March 12, 2017 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fc/712d41682cccdfa559e48b665b6bc781 to your computer and use it in GitHub Desktop.
Save fc/712d41682cccdfa559e48b665b6bc781 to your computer and use it in GitHub Desktop.
// 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