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

Refactor to calculate data at render time #265

Merged
merged 3 commits into from
Nov 14, 2016
Merged

Conversation

tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Oct 12, 2016

WIP for #264

Issues outstanding

  1. I think observableQuery.currentResult() should return errors also. Need to PR AC for that.
  2. Slight weirdness with needing to store previousData. Moving forward we should just be able to blindly pass currentResult through; perhaps AC should cache previousData. But hopefully what I'm doing works for now.
  3. A bunch of tests failing, some due to the above, need to investigate more.

@@ -191,14 +191,18 @@ export default function graphql(
return opts;
}

function shouldSkip(props) {
return mapPropsToSkip(props) || (mapPropsToOptions(props) as QueryOptions).skip;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does end up calling mapPropsToOptions more often than before. Dunno if that's a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we should probably just do that once in willRecieveProps (and initially).

I wouldn't expect people would have assumptions about how many times it's called though.

@jbaxleyiii
Copy link
Contributor

@tmeasday any updates on this?

@tmeasday
Copy link
Contributor Author

Good question, I'll try to get back to this next week. Would be a useful change I think.

@tmeasday tmeasday changed the title WIP - refactor to calculate data at render time Refactor to calculate data at render time Nov 7, 2016
@tmeasday
Copy link
Contributor Author

tmeasday commented Nov 7, 2016

@jbaxleyiii this is now ready to go.

@tmeasday
Copy link
Contributor Author

tmeasday commented Nov 7, 2016

Ok, there's a bug in AC that needs to be addressed, so hold fire until then (it's causing the test to timeout)

@tmeasday
Copy link
Contributor Author

tmeasday commented Nov 7, 2016

See: apollographql/apollo-client#878

@tmeasday
Copy link
Contributor Author

@jbaxleyiii I'm not sure if you want to have a final review of this, but this is ready to go. Would like to merge it into the next release.

@jbaxleyiii
Copy link
Contributor

@tmeasday on it!

@jbaxleyiii
Copy link
Contributor

@tmeasday man thats fantastic! Go for it!

@tmeasday tmeasday merged commit 1c85c07 into master Nov 14, 2016
this.data = assign({}, defaultQueryData) as any;
this.createQuery(opts);
}
this.createQuery(opts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we now call createQuery unconditionally on setInitialProps (for non-mutations), even if the query is initially skipped. Isn't that wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are OK now because we don't even get to setInitialProps if we are skipping: https://github.com/apollostack/react-apollo/blob/bd2f887a559c2fe1ba7b3b89e9b337e3223a9402/src/graphql.tsx#L261

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, whoops, I was imagining that setInitialProps was a React lifecycle API like getInitialState.

@calebmer calebmer deleted the 264-data-at-render-time branch March 1, 2017 18:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants