Module: React::Callbacks::ClassMethods

Defined in:
lib/react/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#callbacks_for(callback_name) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/react/callbacks.rb', line 32

def callbacks_for(callback_name)
  wrapper_name = "_#{callback_name}_callbacks"
  if superclass.respond_to? :callbacks_for
    superclass.callbacks_for(callback_name)
  else
    []
  end + send(wrapper_name)
end

#define_callback(callback_name, &after_define_hook) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/react/callbacks.rb', line 20

def define_callback(callback_name, &after_define_hook)
  wrapper_name = "_#{callback_name}_callbacks"
  define_singleton_method(wrapper_name) do
    Hyperloop::Context.set_var(self, "@#{wrapper_name}", force: true) { [] }
  end
  define_singleton_method(callback_name) do |*args, &block|
    send(wrapper_name).concat(args)
    send(wrapper_name).push(block) if block_given?
    after_define_hook.call(*args, &block) if after_define_hook
  end
end