-
Notifications
You must be signed in to change notification settings - Fork 13
list_components_as
method
#159
Comments
Could you elaborate more on how this pattern is used? Also is |
pretty much says it all.. Sometimes you want to know all the components instantiated in a class. You can do it today using before_mount/after_mount to keep track, but why not just make a method that does it. |
See https://github.com/ruby-hyperloop/ruby-hyperloop.io/wiki/Keeping-Track-of-Multiple-Components for a real-world use case. |
Perhaps a more useful way to do this is to use an "event" approach like http://notes.jetienne.com/2011/03/22/microeventjs.html For example: class AForm < React::Component::Base
include MicroEvents::Receiver
param :name
on_event :close do
if state.opened!(false) # keep in mind bang methods return the current state
state.message! "I am closing..."
after(2) { state.message! nil }
end
end
render(DIV) do
"I am #{params.name} ".span
if state.opened
BUTTON { 'close me' }.on(:click) { close }
else
BUTTON { 'open me' }.on(:click) { state.opened! true }
end
state.message.span if state.message
end
end
class App < React::Component::Base
render(DIV) do
AForm(name: 'form 1')
AForm(name: 'form 2')
BUTTON { 'Close All' }.on(:click) { MicroEvent.close }
end
end |
I actually like this MicroEvents pattern more. It decouples the |
Agree... I think I will add a HyperEvent gem this week, and close this problem if it seem to fit the bill. See https://github.com/ruby-hyperloop/ruby-hyperloop.io/wiki/Keeping-Track-of-Multiple-Components (at the end) for example |
Implement the following pattern
with this macro
You could of course implement a
components
method that works for all classes, but this way you only have the (slight) overhead when you really need it...The text was updated successfully, but these errors were encountered: