-
Notifications
You must be signed in to change notification settings - Fork 148
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
Routes path specs #135
Routes path specs #135
Conversation
|
||
context "when params" do | ||
it "should show inbox spec" do | ||
expect(evaljs("Routes.inbox_path.params").map{|v| v }).to eq(["_id", "options"]) |
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've implemented _
as a prefix for parameter name for the case of collision with javascript reserved word. Ex. /returns/:return
- JS function generated from this route using previous implementation required the underscore otherwise JS would not complile function(return, options) {}
because of reserved name return
.
I think this solution is not required now at all and params should return id
without underscore.
@bogdan fixed. |
@bogdan ping :) |
@@ -192,6 +215,15 @@ Utils = | |||
prefix | |||
|
|||
# | |||
# route function: create route path function and add spec to it | |||
# | |||
route: (required_params, required_parts, optional_parts, route_spec) -> |
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.
What is the difference between required_params
and required_parts
? Why can't we use only one of them?
Fixed |
#{route_name}: function(#{build_params(required_parts)}) { | ||
return Utils.build_path(#{json(required_parts)}, #{json(optional_parts)}, #{json(serialize(route.path.spec, parent_spec))}, arguments); | ||
}#{",\n" + url_link if url_link.length > 0} | ||
#{route_name}: Utils.route(#{build_params(required_parts, true)}, #{json(required_parts)}, #{json(optional_parts)}, #{json(serialize(route.path.spec, parent_spec))}, arguments)#{",\n" + url_link if url_link.length > 0} |
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.
It will be hard to guess the required parameters based on currently generated code:
inbox_message_path: Utils.route(["inbox_id", "id"], "inbox_id", "id", ....)
If we can not make it clear than lets make an extra line of comments that shows the correct function signature, like:
// function(inbox_id, id, options)
Done :) |
It will be hard to guess the required parameters based on currently generated code: inbox_message_path: Utils.route(["inbox_id", "id"], ["format"], ....) If we can not make it clear than lets make an extra line of comments that shows the correct function signature, like: // function(inbox_id, id, options) |
Done 😀 |
#{route_name}: function(#{build_params(required_parts)}) { | ||
return Utils.build_path(#{json(required_parts)}, #{json(optional_parts)}, #{json(serialize(route.path.spec, parent_spec))}, arguments); | ||
}#{",\n" + url_link if url_link.length > 0} | ||
// function(#{required_parts.join(', ')}) |
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.
options
should be part of signature.
This one looks good, but want to merge #137 first. This one is easier so it will be easier to merge conflicts here than there. |
@bogdan no problem. I just squashed commits, because it was too much for this pull request :) |
Routes.users_path() // => "/users" | ||
'' + Routes.user_path // => "/users/:id(.:format)" | ||
Routes.user_path.toString() // => "/users/:id(.:format)" | ||
Routes.user_path.required_params // => ['id'] |
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.
These are advanced things. Lets extract them to its own part of readme.
Don't want tricky features to be mixed with core.
Done |
🎉 🆒 Thanks! |
Based by #123 , but here we don't have separate function
spec
to get spec of route. We overridetoString
for route function, and this give for us to get function spec in this way: