Last active
November 24, 2017 03:24
-
-
Save MHerszak/d8c46eea35d08aa1a56579756478fd6f 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
const options = { | |
name: 'posts.item', | |
// Which key should become data key for state in hoc | |
key: 'document', | |
// load initial data | |
async selectData(service, props) { | |
// if independent from another components props | |
return service.get(props.documentId) | |
}, | |
// update items on update event | |
updated(result, state, props) { | |
if (result._id === props.documentId) { | |
return Object.assign({}, props.document, result); | |
} | |
return props.document; | |
}, | |
// often patched because | |
patched(result, state, props) { | |
if (result._id === props.documentId) { | |
return Object.assign({}, props.document, result); | |
} | |
return props.document; | |
}, | |
}; | |
@withServiceEvents('posts', options) | |
export default class Posts extends PureComponent { | |
static displayName = 'Posts'; | |
static propTypes = propTypes; | |
static defaultProps = defaultProps; | |
render() { | |
const { component, data } = this.props; | |
return React.createElement(component, { document: data }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment