inesita-rb / inesita

Frontend web application framework in Ruby using Opal.
https://inesita.fazibear.me/
MIT License
259 stars 15 forks source link

after_* hooks #20

Closed elia closed 7 years ago

elia commented 8 years ago

I found to be very useful to initialize stuff after getting the properties, so I ended up addind an after_props hook to allow for it. I think it would be ok to add hooks for the three major events that happen after initialization.

fazibear commented 8 years ago

Here https://github.com/inesita-rb/inesita/blob/master/opal/inesita/component.rb#L8 and https://github.com/inesita-rb/inesita/blob/master/opal/inesita/component_virtual_dom_extension.rb#L19 I have already added an init method that should replace initialize. Same with Store as you can see here https://github.com/inesita-rb/inesita/blob/master/opal/inesita/store.rb#L4 and here https://github.com/inesita-rb/inesita/blob/master/opal/inesita/application.rb#L48.

elia commented 8 years ago

@fazibear that's great, but what I needed specifically is a hook after #with_props, my understanding is that props aren't cached and the init happens at that stage, but I admit I didn't look into how cache works in detail. Any way this can be changed?

fazibear commented 8 years ago

@elia props are passed to component before render. If you need a hook on every possible porps change, you can call it in render method. It's some kind of hack, but it will be same thing as you will add some hooks before calling render.

It would be nice to have before_render hook :)

Example:

def some_hook
  # props are refreshed
end

def render
  some_hook
  div do
    #other markup
  end
end
fazibear commented 7 years ago

Hi, from 0.5.0 you can use before_render callback.