Sha256: 753e6ff8bcd986223d92bc6676e0adaa74798a4be10295b85c282f905ccb4a6d

Contents?: true

Size: 1.36 KB

Versions: 9

Compression:

Stored size: 1.36 KB

Contents

require 'glimmer/dsl/expression'
require 'glimmer/data_binding/model_binding'
require 'glimmer/data_binding/widget_binding'

module Glimmer
  module DSL
    # Responsible for wiring two-way data-binding for text and selection properties
    # on Text, Button, and Spinner widgets.
    # Does so by using the output of the bind(model, property) command in the form
    # of a ModelBinding, which is then connected to an anonymous widget observer
    # (aka widget_data_binder as per widget_data_binders array)
    #
    # Depends on BindCommandHandler
    class DataBindingExpression < Expression
      def can_interpret?(parent, keyword, *args, &block)
        args.size == 1 and
        args[0].is_a?(DataBinding::ModelBinding)
      end

      def interpret(parent, keyword, *args, &block)
        model_binding = args[0]
        widget_binding_parameters = [parent, keyword]
        widget_binding = DataBinding::WidgetBinding.new(*widget_binding_parameters)
        widget_binding.call(model_binding.evaluate_property)
        #TODO make this options observer dependent and all similar observers in widget specific data binding handlers
        widget_binding.observe(model_binding)
        # TODO simplify this logic and put it where it belongs
        parent.add_observer(model_binding, keyword) if parent.respond_to?(:add_observer, [model_binding, keyword])
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
glimmer-0.5.11 lib/glimmer/dsl/data_binding_expression.rb
glimmer-0.5.10 lib/glimmer/dsl/data_binding_expression.rb
glimmer-0.5.9 lib/glimmer/dsl/data_binding_expression.rb
glimmer-0.5.8 lib/glimmer/dsl/data_binding_expression.rb
glimmer-0.5.7 lib/glimmer/dsl/data_binding_expression.rb
glimmer-0.5.6 lib/glimmer/dsl/data_binding_expression.rb
glimmer-0.5.5 lib/glimmer/dsl/data_binding_expression.rb
glimmer-0.5.4 lib/glimmer/dsl/data_binding_expression.rb
glimmer-0.5.3 lib/glimmer/dsl/data_binding_expression.rb