Skip to content

Instantly share code, notes, and snippets.

@MHerszak
Last active November 24, 2017 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MHerszak/d8c46eea35d08aa1a56579756478fd6f to your computer and use it in GitHub Desktop.
Save MHerszak/d8c46eea35d08aa1a56579756478fd6f to your computer and use it in GitHub Desktop.
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