2017-12-27 00:54:28 +00:00
|
|
|
import { injectIntl } from 'react-intl';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2017-12-24 06:16:45 +00:00
|
|
|
// Merges react-redux props.
|
|
|
|
export function mergeProps (stateProps, dispatchProps, ownProps) {
|
|
|
|
Object.assign({}, ownProps, {
|
|
|
|
dispatch: Object.assign({}, dispatchProps, ownProps.dispatch || {}),
|
|
|
|
state: Object.assign({}, stateProps, ownProps.state || {}),
|
|
|
|
});
|
|
|
|
}
|
2017-12-27 00:54:28 +00:00
|
|
|
|
|
|
|
// Connects a component.
|
|
|
|
export function wrap (Component, mapStateToProps, mapDispatchToProps, options) {
|
|
|
|
const withIntl = typeof options === 'object' ? options.withIntl : !!options;
|
|
|
|
return (withIntl ? injectIntl : i => i)(connect(mapStateToProps, mapDispatchToProps, mergeProps)(Component));
|
|
|
|
}
|