setResourceMeta
Update one or more individual resources with the same metadata.

Arguments

  1. 1.
    options (Object): An object that defines how to update the metadata. The options are as follows:
    • resources (Array|Object): An array of the resources, or resource IDs, to update with the new meta.
    • newMeta (Object): The meta to set on each of the resources.
    • meta (Object): The current resource meta object from this resource's store slice. Optional when mergeMeta is false, required otherwise.
    • [initialResourceMeta] (Object): Additional metadata to add to any resource that previously did not have meta.
    • [mergeMeta] (Boolean): Whether or not to merge a resource's old metadata with the new metadata. Defaults to true.

Returns

(Object): The new resource meta object.

Example

1
import { setResourceMeta } 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.SELECT_MANY_RESOURCES): {
7
const meta = setResourceMeta({
8
resources: action.resources,
9
meta: state.meta,
10
newMeta: {
11
selected: true
12
}
13
});
14
15
return {
16
...state,
17
meta
18
};
19
}
20
}
21
}
Copied!

Tips

  • This is used internally within the reducer returned by
    resourceReducer to update the resource meta in your
    state tree. You will typically only need to use this method if you're writing