Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRY out data suffix handling #7419

Merged
merged 3 commits into from
Oct 28, 2022
Merged

DRY out data suffix handling #7419

merged 3 commits into from
Oct 28, 2022

Conversation

Rich-Harris
Copy link
Member

A thought I had while reviewing #7416 — our data suffix handling is a bit raggedy, and would maybe be nicer if we encapsulated the repetitious logic into helper functions.

No changeset or tests needed for this change

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2022

⚠️ No Changeset found

Latest commit: 1fb72d4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Rich-Harris Rich-Harris changed the title Data suffix DRY out data suffix handling Oct 28, 2022
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

One suggestion, but I'm fine with it either way


/** @param {string} pathname */
export function strip_data_suffix(pathname) {
return pathname.slice(0, -DATA_SUFFIX.length);
Copy link
Member

Choose a reason for hiding this comment

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

should we use has_data_suffix here and make this a noop in case it's not the suffix? Would reduce code at one call site.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not a huge fan of functions that are 'forgiving' about their inputs — it adds modest convenience (albeit at a single call site in our case, IOW it's just moving the logic around rather than reducing repetition) at the cost of greater uncertainty and wasted computation (however negligible)

@Rich-Harris Rich-Harris merged commit 219860f into master Oct 28, 2022
@Rich-Harris Rich-Harris deleted the data-suffix branch October 28, 2022 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants