Class: Glimmer::DataBinding::ElementBinding
- Inherits:
-
Object
- Object
- Glimmer::DataBinding::ElementBinding
- Includes:
- Glimmer, Observable, Observer
- Defined in:
- lib/glimmer/data_binding/element_binding.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#property ⇒ Object
readonly
Returns the value of attribute property.
Instance Method Summary collapse
- #call(value) ⇒ Object
- #evaluate_property ⇒ Object
-
#initialize(element, property, translator = nil) ⇒ ElementBinding
constructor
A new instance of ElementBinding.
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
#element ⇒ Object (readonly)
Returns the value of attribute element.
12 13 14 |
# File 'lib/glimmer/data_binding/element_binding.rb', line 12 def element @element end |
#property ⇒ Object (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_property ⇒ Object
31 32 33 |
# File 'lib/glimmer/data_binding/element_binding.rb', line 31 def evaluate_property @element.send(@property) end |