upsertResources
Add new or update existing resources in your state tree.

Arguments

  1. 1.
    resources (Object): The current resources object from your state tree.
  2. 2.
    newResources (Array|Object): The new resources to add or update.
  3. 3.
    [mergeResources] (Boolean): Whether or not to merge individual resources with the existing resource in the store, or to replace it with the new data. Defaults to true.

Returns

(Object): The updated resources object.

Example

1
import { upsertResources } from 'redux-resource';
2
import actionTypes from './my-action-types';
3
4
export default function reducer(state, action) {
5
switch (action.type) {
6
case (actionTypes.CREATE_RESOURCES_CUSTOM): {
7
const newResources = upsertResources({
8
resources: state.resources,
9
newResources: action.resources
10
});
11
12
return {
13
...state,
14
resources: newResources
15
};
16
}
17
}
18
}
Copied!

Tips

  • This is used internally within the reducer returned by
    resourceReducer to add and update resources in the
    store. You will typically only need to use this function if you're authoring a
    plugin.
Last modified 3yr ago