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

Enhance/compose paths #11

Merged
merged 7 commits into from
Jul 17, 2018
Merged

Enhance/compose paths #11

merged 7 commits into from
Jul 17, 2018

Conversation

TejasQ
Copy link
Contributor

@TejasQ TejasQ commented Jul 16, 2018

Why

Currently, when using Poll, every Get inside it has its path appended to whatever Poll's path was. But why? Typically, a user would want to poll a specific endpoint and not have it affect subsequent GET requests. This PR solves this case.

It also removes the possibility of nesting Poll paths, which generally is a bad practice. Why would anyone nest Polls?

@TejasQ TejasQ self-assigned this Jul 16, 2018
@TejasQ TejasQ requested a review from fabien0102 July 16, 2018 14:52
Copy link
Contributor

@fabien0102 fabien0102 left a comment

Choose a reason for hiding this comment

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

Can you add some docs about this API? It's quite hard to review with this ts-lint mess

@TejasQ TejasQ force-pushed the enhance/compose-paths branch from 456979c to 7005a07 Compare July 16, 2018 15:15
@TejasQ
Copy link
Contributor Author

TejasQ commented Jul 16, 2018

I can do one better and clean up the lint fix. Just commit --amended for your reading pleasure.

src/Get.tsx Outdated
componentDidMount() {
this.shouldFetchImmediately() && this.fetch();
public static getDerivedStateFromProps(props: Pick<GetComponentProps, "wait" | "lazy">) {
return { loading: !props.lazy };
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't use wait anymore? and what is wait btw? ^^

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 tried to be clear about what wait is here.

I wonder how we can make it more clear. 🤔

Basically, if wait is set, it doesn't render anything until there is data.

// If the path or base prop changes, refetch!
const { path, base } = this.props;
if (prevProps.path !== path || prevProps.base !== base) {
this.shouldFetchImmediately() && this.fetch();
if (!this.props.lazy) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use this.state.loading here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the logic flow here is simply:

  • did something change? 🤔
  • does the user want to lazy load? 🤔
  • DONT DO ANYTHING.

It doesn't quite depend on loading state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but if I'm in loading, that means that I have a request pending, so 2 (or more) requests can arrive in this case -> carefull to concurrency 💥

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's tackle this in a separate PR. I made an issue (#12) where we can handle this.

src/Get.tsx Outdated
const { base, path } = this.props;
this.setState(() => ({ error: "", loading: true }));

const { resolve } = this.props;
const foolProofResolve = resolve || (data => data);
const foolProofResolve = resolve || (noop => noop);
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically, noop means no operation, and it's a classic function name that represent () => {}.

I think that I prefer the old data => data here ;)

@TejasQ TejasQ mentioned this pull request Jul 16, 2018
Copy link
Contributor

@fabien0102 fabien0102 left a comment

Choose a reason for hiding this comment

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

Looks good, even if I really miss the unit tests for this kind of PR 🙈

@TejasQ TejasQ merged commit 921a749 into next Jul 17, 2018
@TejasQ TejasQ deleted the enhance/compose-paths branch July 17, 2018 15:48
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.

2 participants