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

Clean up the parameters that are passed to the handler #114

Merged
merged 5 commits into from
Jan 10, 2017

Conversation

jeffposnick
Copy link
Contributor

R: @addyosmani @gauntface

Fixes #107

This leads to less cruft being passed along to the handler's params when using the RegExpRoute or ExpressRoute classes along with capture groups/named parameters.

I've got some tests for this module in flight at https://github.com/GoogleChrome/sw-helpers/tree/sw-routing-tests and I'll add tests for this modified functionality as part of a PR for that branch.

// If the route does match, then collect values for all the named
// parameters that were returned in keys.
// If there are no named parameters then this will end up returning {},
// which is truthy, and therefore a sufficient return value.

Choose a reason for hiding this comment

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

What happens to the params value when there is no capture groups? Previously it was true which didn't feel like the right value given what it represents.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As per the inline comment in the code:

If there are no named parameters then this will end up returning {}...

That will result in params being set to {}, which seemed reasonable to me. Do you think a different value would make more sense? It needs to be something truthy.

Choose a reason for hiding this comment

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

Personally I'd expect params to be undefined if the route defines no routes. The match method needs to be truthy, but the callback to the developer facing API could have this filtered out if the value is not an object, meaning you could return true and it would get parsed out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I've updated the code to behave the way you describe.

@jeffposnick
Copy link
Contributor Author

Travis is failing because the new sw-lib tests have landed in master while this PR has been in flight, and they need to be adjusted to account for the revised params behavior. I'll add a commit to this PR that cleans those up.

@jeffposnick
Copy link
Contributor Author

Merging now that Travis CI is happy.

It's always a good sign when tests break when interfaces change 😄

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