Class: Glimmer::DataBinding::ElementBinding

Inherits:
Object
  • Object
show all
Includes:
Glimmer, Observable, Observer
Defined in:
lib/glimmer/data_binding/element_binding.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, property, translator = nil) ⇒ ElementBinding

Returns a new instance of ElementBinding.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/glimmer/data_binding/element_binding.rb', line 13

def initialize(element, property, translator = nil)
  @element = element
  @property = property
  @translator = translator || proc {|value| value}

  # TODO see if this is needed in Opal
#         if @element.respond_to?(:dispose)
#           @element.on_widget_disposed do |dispose_event|
#             unregister_all_observables
#           end
#         end
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



12
13
14
# File 'lib/glimmer/data_binding/element_binding.rb', line 12

def element
  @element
end

#propertyObject (readonly)

Returns the value of attribute property.



12
13
14
# File 'lib/glimmer/data_binding/element_binding.rb', line 12

def property
  @property
end

Instance Method Details

#call(value) ⇒ Object



26
27
28
29
# File 'lib/glimmer/data_binding/element_binding.rb', line 26

def call(value)
  converted_value = translated_value = @translator.call(value)
  @element.set_attribute(@property, converted_value) unless evaluate_property == converted_value
end

#evaluate_propertyObject



31
32
33
# File 'lib/glimmer/data_binding/element_binding.rb', line 31

def evaluate_property
  @element.send(@property)
end