Class: Volt::BaseBinding

Inherits:
Object show all
Defined in:
lib/volt/page/bindings/base_binding.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(volt_app, target, context, binding_name) ⇒ BaseBinding

Returns a new instance of BaseBinding.



15
16
17
18
19
20
21
22
# File 'lib/volt/page/bindings/base_binding.rb', line 15

def initialize(volt_app, target, context, binding_name)
  @volt_app     = volt_app
  @target       = target
  @context      = context
  @binding_name = binding_name

  @@binding_number ||= 10_000
end

Instance Attribute Details

#binding_nameObject

Returns the value of attribute binding_name.



13
14
15
# File 'lib/volt/page/bindings/base_binding.rb', line 13

def binding_name
  @binding_name
end

#contextObject

Returns the value of attribute context.



13
14
15
# File 'lib/volt/page/bindings/base_binding.rb', line 13

def context
  @context
end

#targetObject

Returns the value of attribute target.



13
14
15
# File 'lib/volt/page/bindings/base_binding.rb', line 13

def target
  @target
end

#volt_appObject

Returns the value of attribute volt_app.



13
14
15
# File 'lib/volt/page/bindings/base_binding.rb', line 13

def volt_app
  @volt_app
end

Instance Method Details

#browserObject



24
25
26
# File 'lib/volt/page/bindings/base_binding.rb', line 24

def browser
  @volt_app.browser
end

#dom_sectionObject



28
29
30
# File 'lib/volt/page/bindings/base_binding.rb', line 28

def dom_section
  @dom_section ||= target.dom_section(@binding_name)
end

#getter_fail(error) ⇒ Object

log out a message about a failed computation or Promise.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/volt/page/bindings/base_binding.rb', line 46

def getter_fail(error)
  message = "#{self.class.to_s} Error: #{error.inspect}"

  if RUBY_PLATFORM == 'opal'
    if `#{@getter}`
      message += "\n" + `#{@getter}.toString()`
    end
  else
    if error.respond_to?(:backtrace)
      message += "\n" + error.backtrace.join("\n")
    end
  end

  Volt.logger.error(message)
end

#removeObject



32
33
34
35
36
37
38
39
# File 'lib/volt/page/bindings/base_binding.rb', line 32

def remove
  @dom_section.remove if @dom_section

  # Clear any references
  @target      = nil
  @context     = nil
  @dom_section = nil
end

#remove_anchorsObject



41
42
43
# File 'lib/volt/page/bindings/base_binding.rb', line 41

def remove_anchors
  @dom_section.remove_anchors if @dom_section
end