Class: Glimmer::DSL::Tk::DataBindingExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/glimmer/dsl/tk/data_binding_expression.rb

Overview

Responsible for wiring two-way data-binding. 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

Depends on BindCommandHandler

Instance Method Summary collapse

Instance Method Details

#can_interpret?(parent, keyword, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/glimmer/dsl/tk/data_binding_expression.rb', line 35

def can_interpret?(parent, keyword, *args, &block)
  args.size == 1 and
    args[0].is_a?(DataBinding::ModelBinding)
end

#interpret(parent, keyword, *args, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/glimmer/dsl/tk/data_binding_expression.rb', line 40

def interpret(parent, keyword, *args, &block)
  model_binding = args[0]
  widget_binding_parameters = [parent, keyword]
  widget_binding = DataBinding::Tk::WidgetBinding.new(*widget_binding_parameters)
  #TODO make this options observer dependent and all similar observers in widget specific data binding handlers
  registration = widget_binding.observe(model_binding)
  parent.on('destroy') { registration.deregister }

  # 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])
  widget_binding.call(model_binding.evaluate_property)
end