Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export type DefaultQueryStringMap = {
};

export interface UrlHelpers {
getUrl: () => string;
getUrl: () => string | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's optional, let's add a question mark instead; what do you think?

Copy link
Contributor Author

@Mudaafi Mudaafi Feb 28, 2024

Choose a reason for hiding this comment

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

It's not that it's optional, but rather that the function can return undefined on server-side. I can modify it to return null instead if that makes more sense. See this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Challenge me on this, please if you think otherwise. But I like to reserve undefined for values that haven't been passed or haven't had any operations.

Copy link
Contributor Author

@Mudaafi Mudaafi Feb 28, 2024

Choose a reason for hiding this comment

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

Fair enough, I was thinking along the lines of either

  • A function that doesn't have a return value
  • On the server --> may as well have not run getUrl --> Effectively no operations --> undefined

but I'm not too picky about it. I guess a better way to decide is what should getUrl return on the server if it's not supposed to run? In code:

getUrl() {
  if (typeof window === 'undefined') {
    // Option 1
    return; // undefined

    // Option 2
    return null; // explicitly null
...
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually after you laying out like this, not sure anymore 😅

setUrl: (newUrlWithEncodedState: string) => void;
getStateFromUrl: (urlString: string) => RequestConfigs;
getUrlFromState: (state: RequestConfigs, options: QueryParamEncodingOptions) => string;
Expand Down