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

Refactor URL handling to account for query params #13

Merged
merged 4 commits into from
Jul 18, 2018
Merged

Conversation

TejasQ
Copy link
Contributor

@TejasQ TejasQ commented Jul 18, 2018

Why

Currently, when requesting /collection/resource?filter=blah, nested Get, Mutate and Poll components naïvely append things past the query string. This leads to incorrect behavior.

This PR makes URL handling more reliable by treating query strings as they should be treated.

Side effects

This PR also makes the following optimizations/adjustments to the codebase:

  • Adds missing TSLint dependencies (how was the linter working? 🤔)
  • Adds better handling of defaultProps.
  • Removes unnecessary getDerivedStateFromProps because we only want initial state from props since Gets are not fully controlled.

@TejasQ TejasQ requested a review from fabien0102 July 18, 2018 11:17
@TejasQ TejasQ self-assigned this Jul 18, 2018
@TejasQ TejasQ requested a review from peterszerzo July 18, 2018 11:25
src/Get.tsx Outdated
public static getDerivedStateFromProps(props: Pick<GetComponentProps, "lazy">) {
return { loading: !props.lazy };
}

public static defaultProps = {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should type your defaultProps here

src/Get.tsx Outdated
@@ -159,9 +161,11 @@ class ContextlessGet<T> extends React.Component<GetComponentProps<T>, Readonly<G
};

public fetch = async (requestPath?: string, thisRequestOptions?: RequestInit) => {
const { base, path, resolve } = this.props;
const { base, path, resolve } = this.props as PropsWithDefaults<T>;
Copy link
Contributor

Choose a reason for hiding this comment

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

So bad… we can fix this together ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Come on then, show me how it's done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TejasQ TejasQ merged commit e995322 into next Jul 18, 2018
@TejasQ TejasQ deleted the enhance/query-params branch July 18, 2018 13:32
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