-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Moving params in to HTTP::Server::Context #1509
Conversation
…context is, and ensures we only parse once per request. Fixes #1473
@@ -4,6 +4,7 @@ abstract class Lucky::Action | |||
getter :context, :route_params | |||
|
|||
def initialize(@context : HTTP::Server::Context, @route_params : Hash(String, String)) | |||
context.params.route_params = @route_params |
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 feels weird putting this here, but where else would it go?
memoize def params : Lucky::Params | ||
context.params | ||
end |
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 basically just so you can still call params
in your actions without having to call context.params
.
|
||
@_params : Lucky::Params? | ||
|
||
def params : Lucky::Params |
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.
Side bonus, params
is now available in all Components thanks to #1488
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.
🎉
Purpose
Fixes #1473
This is my stab at solving #1473
Description
The original issue was that we were instantiating the params object twice. This lets us do it just once by moving it in to context.
The only strange thing I'm not too sure on is the whole part of setting
route_params
later. I don't think it affects anything here, but I for sure want another set of eyes on this one.Checklist
crystal tool format spec src
./script/setup
./script/test