Files
Readarr/frontend/src/Store/connectSection.js
Tynan CR 9d00a17ade Fixed eslint errors and re-enabled build.sh check (#150)
* Fixed eslint errors and re-enabled build.sh check

* Corrected typo

* Corrected typo

* Disabled max-params on files with warnings

* Fixes for PR comments

* Fixes for PR comments

* Fixes for PR comments

* Fixes for PR comments

* Fixes for PR comments

* Fixes for PR comments
2017-12-17 00:49:47 -05:00

59 lines
1.3 KiB
JavaScript

/* eslint max-params: 0 */
import React, { Component } from 'react';
import { connect } from 'react-redux';
import getDisplayName from 'Helpers/getDisplayName';
function connectSection(mapStateToProps, mapDispatchToProps, mergeProps, options = {}, sectionOptions = {}) {
return function wrap(WrappedComponent) {
const ConnectedComponent = connect(mapStateToProps, mapDispatchToProps, mergeProps, options)(WrappedComponent);
class Section extends Component {
//
// Control
getWrappedInstance = () => {
if (this._wrappedInstance) {
return this._wrappedInstance.getWrappedInstance();
}
}
//
// Listeners
setWrappedInstanceRef = (ref) => {
this._wrappedInstance = ref;
}
//
// Render
render() {
if (options.withRef) {
return (
<ConnectedComponent
ref={this.setWrappedInstanceRef}
{...sectionOptions}
{...this.props}
/>
);
}
return (
<ConnectedComponent
{...sectionOptions}
{...this.props}
/>
);
}
}
Section.displayName = `Section(${getDisplayName(WrappedComponent)})`;
Section.WrappedComponent = WrappedComponent;
return Section;
};
}
export default connectSection;