Skip to content

Commit

Permalink
convert to hoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesPortelli committed Nov 9, 2016
1 parent e2ee64e commit 08ca938
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions src/addons/editors/ContainerEditorWrapper.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
import React, { Component } from 'react';

// Wrapper componenet used when having an editor which is a redux container.
// Wrapper HOC used when having an editor which is a redux container.
// Required since react-data-grid requires access to getInputNode, getValue,
// howvever when doing this.getEditor() in react-data-grid we get a react
// componenet wrapped by the redux connect function and thus wont have access
// to the required methods.
export class ContainerEditorWrapper extends Component {
constructor(props, context) {
super(props, context);

this.setEditorRef = this.setEditorRef.bind(this);
}

getInputNode() {
return this.editorRef.getInputNode();
}

getValue() {
return this.editorRef.getValue();
}

setEditorRef(ref) {
this.editorRef = ref;
}

render() {
let EditorComponent = this.props.editorComponent;
return (<EditorComponent refCallback={this.setEditorRef} {...this.props} />);
}
}

ContainerEditorWrapper.propTypes = {
value: React.PropTypes.string.isRequired,
column: React.PropTypes.object.isRequired,
rowData: React.PropTypes.isRequired,
editorComponent: React.PropTypes.object.isRequired
export default (ContainerEditor) => {
return class ContainerEditorWrapper extends Component {
getInputNode() {
return this.editorRef.getInputNode();
}

getValue() {
return this.editorRef.getValue();
}

render() {
return (<ContainerEditor refCallback={(ref) => { this.editorRef = ref; }} {...this.props} />);
}
};
};

export default ContainerEditorWrapper;

0 comments on commit 08ca938

Please sign in to comment.