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

Moving params in to HTTP::Server::Context #1509

Merged
merged 1 commit into from
May 29, 2021
Merged

Moving params in to HTTP::Server::Context #1509

merged 1 commit into from
May 29, 2021

Conversation

jwoertink
Copy link
Member

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

  • - An issue already exists detailing the issue/or feature request that this PR fixes
  • - All specs are formatted with crystal tool format spec src
  • - Inline documentation has been added and/or updated
  • - Lucky builds on docker with ./script/setup
  • - All builds and specs pass on docker with ./script/test

…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
Copy link
Member Author

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?

Comment on lines +2 to 4
memoize def params : Lucky::Params
context.params
end
Copy link
Member Author

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
Copy link
Member Author

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

Copy link
Member

@matthewmcgarvey matthewmcgarvey left a comment

Choose a reason for hiding this comment

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

🎉

@jwoertink jwoertink merged commit b54bc3c into master May 29, 2021
@jwoertink jwoertink deleted the issues/1473 branch May 29, 2021 00:02
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.

Parsing Lucky::Params twice per request
2 participants