Class: Glimmer::DSL::Opal::ObserveExpression

Inherits:
StaticExpression
  • Object
show all
Includes:
TopLevelExpression
Defined in:
lib/glimmer/dsl/opal/observe_expression.rb

Constant Summary collapse

REGEX_NESTED_OR_INDEXED_PROPERTY =
/([^\[]+)(\[[^\]]+\])?/

Instance Method Summary collapse

Instance Method Details

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

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/glimmer/dsl/opal/observe_expression.rb', line 14

def can_interpret?(parent, keyword, *args, &block)
  keyword == 'observe' and
    block_given? and
    (args.size == 2) and
    textual?(args[1])
end

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



21
22
23
24
25
26
27
28
# File 'lib/glimmer/dsl/opal/observe_expression.rb', line 21

def interpret(parent, keyword, *args, &block)
  observer = DataBinding::Observer.proc(&block)
  if args[1].to_s.match(REGEX_NESTED_OR_INDEXED_PROPERTY)
    observer.observe(DataBinding::ModelBinding.new(args[0], args[1]))
  else
    observer.observe(args[0], args[1])
  end
end