Class: Volt::EventBinding
- Inherits:
-
BaseBinding
- Object
- BaseBinding
- Volt::EventBinding
- Defined in:
- lib/volt/page/bindings/event_binding.rb
Instance Attribute Summary collapse
-
#binding_name ⇒ Object
Returns the value of attribute binding_name.
-
#context ⇒ Object
Returns the value of attribute context.
Attributes inherited from BaseBinding
Instance Method Summary collapse
-
#initialize(volt_app, target, context, binding_name, event_name, call_proc) ⇒ EventBinding
constructor
A new instance of EventBinding.
-
#remove ⇒ Object
Remove the event binding.
Methods inherited from BaseBinding
#dom_section, #getter_fail, #page, #remove_anchors
Constructor Details
#initialize(volt_app, target, context, binding_name, event_name, call_proc) ⇒ EventBinding
Returns a new instance of EventBinding.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/volt/page/bindings/event_binding.rb', line 32 def initialize(volt_app, target, context, binding_name, event_name, call_proc) super(volt_app, target, context, binding_name) @event_name = event_name handler = proc do |js_event| event = JSEvent.new(js_event) event.prevent_default! if event_name == 'submit' # Call the proc the user setup for the event in context, # pass in the wrapper for the JS event result = @context.instance_exec(event, &call_proc) # The following doesn't work due to the promise already chained issue. # # Ignore native objects. # result = nil unless BasicObject === result # # if the result is a promise, log an exception if it failed and wasn't # # handled # if result.is_a?(Promise) && !result.next # result.fail do |err| # Volt.logger.error("EventBinding Error: promise returned from event binding #{@event_name} was rejected") # Volt.logger.error(err) # end # end end @listener = page.events.add(event_name, self, handler) end |
Instance Attribute Details
#binding_name ⇒ Object
Returns the value of attribute binding_name.
30 31 32 |
# File 'lib/volt/page/bindings/event_binding.rb', line 30 def binding_name @binding_name end |
#context ⇒ Object
Returns the value of attribute context.
30 31 32 |
# File 'lib/volt/page/bindings/event_binding.rb', line 30 def context @context end |
Instance Method Details
#remove ⇒ Object
Remove the event binding
63 64 65 |
# File 'lib/volt/page/bindings/event_binding.rb', line 63 def remove page.events.remove(@event_name, self) end |