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

Commit

Permalink
skip behavior update
Browse files Browse the repository at this point in the history
  • Loading branch information
machard committed Nov 27, 2016
1 parent 8c1f02f commit affad61
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ export default function graphql(
opts.fragments = flatten(opts.fragments);
}

opts = assign({}, opts, {noFetch: opts.noFetch || !!shouldSkip(props)});

if (opts.variables || !operation.variables.length) return opts;

let variables = {};
Expand Down Expand Up @@ -190,7 +192,6 @@ export default function graphql(
}

function fetchData(props, { client }) {
if (shouldSkip(props)) return false;
if (
operation.type === DocumentType.Mutation || operation.type === DocumentType.Subscription
) return false;
Expand Down Expand Up @@ -258,17 +259,14 @@ export default function graphql(

this.type = operation.type;

if (this.shouldSkip(props)) return;
this.setInitialProps();
}

componentDidMount() {
this.hasMounted = true;
if (this.type === DocumentType.Mutation) return;

if (!this.shouldSkip(this.props)) {
this.subscribeToQuery(this.props);
}
this.subscribeToQuery(this.props);
}

componentWillReceiveProps(nextProps) {
Expand All @@ -280,16 +278,12 @@ export default function graphql(
return;
};

if (this.shouldSkip(nextProps)) {
if (!this.shouldSkip(this.props)) {
// if this has changed, we better unsubscribe
this.unsubscribeFromQuery();
}
return;
}

// we got new props, we need to unsubscribe and re-subscribe with the new data
this.subscribeToQuery(nextProps);

if (this.shouldSkip(this.props) && !this.shouldSkip(nextProps)) {
this.queryObservable.refetch();
}
}

shouldComponentUpdate(nextProps, nextState, nextContext) {
Expand Down Expand Up @@ -461,10 +455,6 @@ export default function graphql(
}

render() {
if (this.shouldSkip(this.props)) {
return createElement(WrappedComponent, this.props);
}

const { shouldRerender, renderedElement, props } = this;
this.shouldRerender = false;

Expand Down

0 comments on commit affad61

Please sign in to comment.