Commit 7626af54 by Kristian Freeman

Pass Date into reducer to keep functions pure

parent 20e17626
......@@ -26,12 +26,14 @@ export function attemptWidgetCreation() {
export function addWidget() {
return {
date: Date.now(),
type: ADD_WIDGET
}
}
export function generateOrder() {
return {
date: Date.now(),
type: GENERATE_ORDER
}
}
......
......@@ -25,7 +25,7 @@ const initialState = {
widgets: []
}
const addWidget = (state) => {
const addWidget = (state, date) => {
const newMaterials = state.materials
newMaterials.dowel.count -= DOWELS_NEEDED
newMaterials.screw.count -= SCREWS_NEEDED
......@@ -34,7 +34,7 @@ const addWidget = (state) => {
let newState = { materials: newMaterials }
if (qaCheck()) {
const newWidget = { created: Date.now() }
const newWidget = { created: date }
const newWidgetsInventory = [].concat(state.widgets, newWidget)
newState.error = null
newState.widgets = newWidgetsInventory
......@@ -51,9 +51,9 @@ const qaCheck = () => {
return check < 7
}
const generateOrder = (state) => {
const generateOrder = (state, date) => {
const newOrder = {
created: Date.now(),
created: date,
widgets: Math.floor(Math.random() * 10) + 1
}
const newOrders = [].concat(state.orders, newOrder)
......@@ -110,9 +110,9 @@ const shipOrder = (state) => {
export default function appState(state = initialState, action) {
switch (action.type) {
case ADD_WIDGET:
return addWidget(state)
return addWidget(state, action.date)
case GENERATE_ORDER:
return generateOrder(state)
return generateOrder(state, action.date)
case ORDER_MATERIALS:
return orderMaterials(state)
case PACKAGE_ORDER:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment