Last active
December 11, 2018 04:28
-
-
Save alex-okrushko/f26b1b0421f6ac2866974593900bd83d to your computer and use it in GitHub Desktop.
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 characters
export function reducer( | |
state: ProductState = initState, | |
action: actions.All | |
): ProductState { | |
switch (action.type) { | |
... | |
case actions.FETCH_PRODUCTS_SUCCESS: { | |
return { | |
// addAll replaces current list of products with new list | |
products: productAdapter.addAll(action.payload, state.products), | |
isLoading: false, | |
}; | |
} | |
case actions.FETCH_PRODUCT_SUCCESS: { | |
return { | |
...state, | |
// upsertOne adds or updates single product with payload data | |
products: productAdapter.upsertOne(action.payload, state.products), | |
}; | |
} | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment