Sha256: 8df5e89ef0de78e05f00aacf3c1ceec7801d895ade3a3c9e56238d22fcdfe5a8

Contents?: true

Size: 917 Bytes

Versions: 5

Compression:

Stored size: 917 Bytes

Contents

require 'glimmer'
require_relative 'observable'
require_relative 'observer'

module Glimmer
  module DataBinding
    class WidgetBinding
      include Glimmer
      include Observable
      include Observer

      attr_reader :widget, :property
      def initialize(model, property, translator = nil)
        @widget = model
        @property = property
        @translator = translator || proc {|value| value}

        if @widget.respond_to?(:dispose)
          @widget.on_widget_disposed do |dispose_event|
            unregister_all_observables
          end
        end
      end
      def call(value)
        converted_value = translated_value = @translator.call(value)
        @widget.set_attribute(@property, converted_value) unless evaluate_property == converted_value
      end
      def evaluate_property
        @widget.get_attribute(@property)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
glimmer-0.5.8 lib/glimmer/data_binding/widget_binding.rb
glimmer-0.5.7 lib/glimmer/data_binding/widget_binding.rb
glimmer-0.5.6 lib/glimmer/data_binding/widget_binding.rb
glimmer-0.5.5 lib/glimmer/data_binding/widget_binding.rb
glimmer-0.5.4 lib/glimmer/data_binding/widget_binding.rb