-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Router add use object params option #3815
base: master
Are you sure you want to change the base?
Router add use object params option #3815
Conversation
@@ -1511,13 +1535,18 @@ | |||
|
|||
// Convert a route string into a regular expression, suitable for matching | |||
// against the current location hash. | |||
_routeToRegExp: function(route) { | |||
_routeToRegExp: function(route, paramNames) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not so keen on modifying passed arguments. Let's bikeshed this decision a bit more (you may have been right in the first place).
I don't like this either, but this feels the least intrusive/most optimal since we are already RegExp parsing the input route string. And we can reuse namedParam
and splatParam
right where they are used.
Since _routeToRegExp()
is only used from route()
, how about moving it's body inside route()
itself? Might be breaking change if someone is ovewritting _routeToRegExp()
though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about moving it's body inside route() itself?
I'm concerned about taking a nice small chunk of reusable, functionally pure code and pulling it out of a method and into the body of an already big method.
I don't have a ton of time to work through this at the moment, but I should be freer next week. Try opening a pull and solicit feedback from other Backbone contributors. Looking forward to seeing this merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what express uses, so passing the array is probably fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this too. What if this method, instead of returning RegExp, returns an object {routeRegExp, paramNames}
. It would keep it functionally pure.
Any backbone guru have time to take a look at this and give me guidance on how to make this better? Thanks! |
if (_.isFunction(name)) { | ||
callback = name; | ||
name = ''; | ||
} | ||
if (!callback) callback = this[name]; | ||
|
||
this._routeInfos = this._routeInfos || {}; | ||
this._routeInfos[route.toString()] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#toString
shouldn't be necessary, it'll be coerced by the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I will update. Thanks.
Updated routed handler to receive Removed the route.toString in hash lookup too. |
Is this PR planned to land on master? |
Adding optional parameter to Router to make route callback handlers called with route params being an object instead of array.
#3799