Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Refactor dataForChild on DocumentType.Mutation to use new bound funct…
Browse files Browse the repository at this point in the history
…ion. (#772)

dataForChild previously returned a new function for type DocumentType.Mutation
causing React shallowEqual render optimizations to fail.

Refactored the mutation specific code into its own method with a binding to
'this' in the constructor.
  • Loading branch information
baerrach authored and James Baxley committed Jul 5, 2017
1 parent 590847b commit 882959b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export default function graphql<TResult = {}, TProps = {}, TChildProps = Default

this.store = this.client.store;
this.type = operation.type;
this.dataForChildViaMutation = this.dataForChildViaMutation.bind(this);
}

componentWillMount() {
Expand Down Expand Up @@ -496,16 +497,18 @@ export default function graphql<TResult = {}, TProps = {}, TChildProps = Default
return (this.refs as any).wrappedInstance;
}

dataForChild() {
if (this.type === DocumentType.Mutation) {
return (mutationOpts: MutationOpts) => {
const opts = this.calculateOptions(this.props, mutationOpts);
dataForChildViaMutation(mutationOpts: MutationOpts) {
const opts = this.calculateOptions(this.props, mutationOpts);

if (typeof opts.variables === 'undefined') delete opts.variables;

if (typeof opts.variables === 'undefined') delete opts.variables;
(opts as any).mutation = document;
return this.client.mutate((opts as any));
}

(opts as any).mutation = document;
return this.client.mutate((opts as any));
};
dataForChild() {
if (this.type === DocumentType.Mutation) {
return this.dataForChildViaMutation;
}

const opts = this.calculateOptions(this.props);
Expand Down

0 comments on commit 882959b

Please sign in to comment.