-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
Implement mount_defaults
#1152
Comments
Just ran into an example where this would have been really fantastic to have access to: class Filters::Form < BaseComponent
needs operation : SaveFilter
needs route : Lucky::RouteHelper
needs button_text : String
def render
form_for route, class: "divide-y divide-gray-200" do
div class: "px-4 py-5 sm:p-6 space-y-4" do
mount Filters::FormFields, operation
end
div class: "px-4 py-4 sm:px-6" do
mount UI::Button, &.submit button_text, data_disable_with: button_loading_text
end
end
end
# Lots of chaining here, but a pretty simple result.
#
# Example:
# ```
# "Create the thing" => "Creating..."
# "Create" => "Creating..."
# "Update blog post" => "Updating..."
# "Update" => "Updating..."
# ```
private def button_loading_text
button_text.split.first.rchop + "ing..."
end
end Because of a lack of |
Before we go down this path, we might want to reference how viewcomponent does this The component has a |
This would be used for a lot more than just mount Header, current_site: current_site, context: context, current_member: current_member
mount List, things: things, current_site: current_site, context: context, current_member: current_member
mount Footer, current_site: current_site, context: context I think abstract class MainLayout
needs current_site : Site
needs context : HTTP::Server::Context
needs current_member : Member
end
class Members::IndexPage < MainLayout
mount_defaults current_site, context
def content
mount List, current_member: current_member
end
end Or this would go in the abstract class BaseComponent < Lucky::Component
mount_defaults current_site, context
end On the page, we might already know the types and methods exist, so maybe it's possible. On the component level, it would be a lot harder. |
Could |
I think in a dynamically typed language this is definitively where I'd put it. In Elixir this kind of thing lives in a context that is pass around to everything. This may not work as well in Crystal though since you'd either have to:
I think mount_defaults would be better suited to Lucky/Crystal since you could get the type-safety. It is not perfect, but I think I'd make the tradeoff of type-safety. I don't love the name though. Definitely open to something else. Since the idea is that
Not sure. Definitely open to ideas |
As described here: #1049 (comment)
The idea is that common
needs
can be passed in automatically. Stuff likecontext
,current_user
The text was updated successfully, but these errors were encountered: