Skip to content

Commit 60a18e7

Browse files
committed
Add default meta via HOCs
1 parent 1cf3205 commit 60a18e7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

client/src/hocs/withResource.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
getOne,
1414
} from '../store/api';
1515

16-
const withResource = resourceKey => (WrappedComponent) => {
16+
const withResource = (resourceType, resourceMeta) => (WrappedComponent) => {
1717
const enhance = compose(
1818
withHandlers({
1919
onSubmit: props => (values, meta = {}) => {
@@ -33,14 +33,14 @@ const withResource = resourceKey => (WrappedComponent) => {
3333

3434
const mapStateToProps = (state, props) => ({
3535
isNew: !props.params.id,
36-
resource: getOne(state, resourceKey, props.params.id),
36+
resource: getOne(state, resourceType, props.params.id),
3737
});
3838

3939
const mapDispatchToProps = dispatch => ({
40-
fetchResource: (payload, meta) => dispatch(fetchOne(resourceKey, payload, meta)),
41-
createResource: (payload, meta) => dispatch(createResource(resourceKey, payload, meta)),
42-
updateResource: (payload, meta) => dispatch(updateResource(resourceKey, payload, meta)),
43-
deleteResource: (payload, meta) => dispatch(deleteResource(resourceKey, payload, meta)),
40+
fetchResource: (payload, meta) => dispatch(fetchOne(resourceType, payload, { ...resourceMeta, ...meta })),
41+
createResource: (payload, meta) => dispatch(createResource(resourceType, payload, { ...resourceMeta, ...meta })),
42+
updateResource: (payload, meta) => dispatch(updateResource(resourceType, payload, { ...resourceMeta, ...meta })),
43+
deleteResource: (payload, meta) => dispatch(deleteResource(resourceType, payload, { ...resourceMeta, ...meta })),
4444
});
4545

4646
return connect(mapStateToProps, mapDispatchToProps)(enhance(WrappedComponent));

client/src/hocs/withResourceList.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
getList,
1414
} from '../store/api';
1515

16-
const withResourceList = resourceKey => (WrappedComponent) => {
16+
const withResourceList = (resourceType, resourceMeta) => (WrappedComponent) => {
1717
const enhance = compose(
1818
withHandlers({
1919
onFilter: props => (filter) => {
@@ -51,14 +51,14 @@ const withResourceList = resourceKey => (WrappedComponent) => {
5151
);
5252

5353
const mapStateToProps = (state, props) => ({
54-
resourceList: getList(state, resourceKey),
54+
resourceList: getList(state, resourceType),
5555
});
5656

5757
const mapDispatchToProps = dispatch => ({
58-
fetchResourceList: (payload, meta) => dispatch(fetchList(resourceKey, payload, meta)),
59-
createResource: (payload, meta) => dispatch(createResource(resourceKey, payload, meta)),
60-
updateResource: (payload, meta) => dispatch(updateResource(resourceKey, payload, meta)),
61-
deleteResource: (payload, meta) => dispatch(deleteResource(resourceKey, payload, meta)),
58+
fetchResourceList: (payload, meta) => dispatch(fetchList(resourceType, payload, {...resourceMeta, ...meta})),
59+
createResource: (payload, meta) => dispatch(createResource(resourceType, payload, {...resourceMeta, ...meta})),
60+
updateResource: (payload, meta) => dispatch(updateResource(resourceType, payload, {...resourceMeta, ...meta})),
61+
deleteResource: (payload, meta) => dispatch(deleteResource(resourceType, payload, {...resourceMeta, ...meta})),
6262
});
6363

6464
return connect(mapStateToProps, mapDispatchToProps)(enhance(WrappedComponent));

0 commit comments

Comments
 (0)