Skip to content

Instantly share code, notes, and snippets.

@alex-okrushko
Last active December 11, 2018 04:28
Show Gist options
  • Save alex-okrushko/f26b1b0421f6ac2866974593900bd83d to your computer and use it in GitHub Desktop.
Save alex-okrushko/f26b1b0421f6ac2866974593900bd83d to your computer and use it in GitHub Desktop.
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