Router add use object params option#3815
Conversation
There was a problem hiding this comment.
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.
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.
This is what express uses, so passing the array is probably fine.
There was a problem hiding this comment.
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! |
backbone.js
Outdated
There was a problem hiding this comment.
#toString shouldn't be necessary, it'll be coerced by the object.
There was a problem hiding this comment.
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