Last active
October 27, 2016 15:59
-
-
Save 4poc/674598e9ac66a1df6948d03488480b17 to your computer and use it in GitHub Desktop.
Revisions
-
Matthias Hecker renamed this gist
Oct 27, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Matthias Hecker created this gist
Oct 27, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ // immutable object assignment: const initialState = { products: {} }; export default function reducer(state = initialState, action = {}) { switch (action.type) { case PUT_PRODUCT: return { ...state, products: { ...state.products, [action.product.id]: action.product } }; default: return state; } } // immutable array insertion: // action.number (number to insert), action.index (array index to insert at) const initialState = { numbers: [] }; export default function reducer(state = initialState, action = {}) { switch (action.type) { case PUT_NUMBER: return { ...state, numbers: [ ...state.numbers.slice(0, action.index), action.number, ...state.numbers.slice(action.index + 1) ] }; default: return state; } }