Instance-level version of Monkeybars::Controller.define_handler. It follows the same syntax as the class-level version but applies the callback block as a listener to events generated by this instance of the controller class’ view. This callback is useful when the application has nested controllers and event handling needs to be different for each instance of a controller class.
define_handler can accept either a single event or a list of events to apply the block to:
define_handler :ok_button_action_performed { puts "action performed on 'ok button'" }
define_handler :ok_button_action_performed, :cancel_button_action_performed { puts "action performed on a button" }
If you are defining a handler that requires aliasing, define handler can also be passed a hash of method => component mappings mixed in with the methods to apply the handler to.
define_handler :text_field_insert_update => "text_field.document" { puts "you typed something" }
define_handler :text_field_insert_update => "text_field.document", :text_field_remove_update => "text_field.document" { puts "you typed or deleted something" }
These mappings can also be mixed in with regular methods. It is suggested that you put all of your hash items at the end of the argument list so they are wrapped up into an implicit Hash object although this is not strictly necessary.
define_handler :ok_button_action_performed, :text_field_insert_update => "text_field.document" { puts "you did ... something" }
# File lib/monkeybars/event_handler_registration_and_dispatch_mixin.rb, line 157 def define_handler(*actions, &block) # define_handler :foo_action_performed => :foo_document_action_performed, { handle event here } actions.each do |action| if action.kind_of? Hash # handle a hash with multiple mappings, e.g. # define_handler :text_field_insert_update => "text_field.document", :text_field2_insert_update => "text_field2.document { ... handler code here ... } action.each do |method, component| @__event_handler_procs[method.to_sym] << block add_implicit_handler_for_method(method, component) end else @__event_handler_procs[action.to_sym] << block add_implicit_handler_for_method(action) end end end
Generated with the Darkfish Rdoc Generator 2.