Skip to content

Commit

Permalink
Do not create new functions in render. Fix #66
Browse files Browse the repository at this point in the history
  • Loading branch information
acontreras89 committed Apr 23, 2017
1 parent 8ee71c9 commit ec4ccf7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/connect-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const connectRequest = (mapPropsToConfigs, options = {}) => WrappedComponent =>
constructor() {
super();

this.forceRequest = this.forceRequest.bind(this)

// A set of URLs that identify all pending requests
this._pendingRequests = {};
this._wrappedInstance = null;
Expand Down Expand Up @@ -115,22 +117,23 @@ const connectRequest = (mapPropsToConfigs, options = {}) => WrappedComponent =>
}
}

render() {
const configs = mapPropsToConfigs(this.props);
const forceRequest = partial(this.requestAsync.bind(this), configs, true, false);
forceRequest() {
this.requestAsync(mapPropsToConfigs(this.props), true, false);
}

render() {
if (withRef) {
return (
<WrappedComponent
{...this.props}
forceRequest={forceRequest}
forceRequest={this.forceRequest}
ref={ref => {
this._wrappedInstance = ref;
}}
/>
);
} else {
return <WrappedComponent {...this.props} forceRequest={forceRequest} />;
return <WrappedComponent {...this.props} forceRequest={this.forceRequest} />;
}
}
}
Expand Down

0 comments on commit ec4ccf7

Please sign in to comment.