Sha256: afc461c569c3af9b5f8e68ef93d627c6e985a61fac7f57ce81ce1af5f8ca5702

Contents?: true

Size: 1.06 KB

Versions: 58

Compression:

Stored size: 1.06 KB

Contents

require 'glimmer/data_binding/observable'
require 'glimmer/data_binding/observer'

module Glimmer
  module DataBinding
    class ElementBinding
      # TODO consider renaming to WidgetBinding since it's no longer dealing with elements directly yet widgets instead
      include Glimmer
      include Observable
      include Observer

      attr_reader :element, :property
      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
      
      def call(value)
        converted_value = translated_value = @translator.call(value)
        @element.set_attribute(@property, converted_value) unless evaluate_property == converted_value
      end
      
      def evaluate_property
        @element.send(@property)
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 2 rubygems

Version Path
glimmer-dsl-web-0.0.5 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-web-0.0.4 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-web-0.0.3 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-web-0.0.2 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-web-0.0.1 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.29.0 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.28.3 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.28.2 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.28.1 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.28.0 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.27.0 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.26.3 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.26.2 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.26.1 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.26.0 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.25.4 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.25.3 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.25.2 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.25.1 lib/glimmer/data_binding/element_binding.rb
glimmer-dsl-opal-0.25.0 lib/glimmer/data_binding/element_binding.rb