Class: Hyalite::TextComponent

Inherits:
Object
  • Object
show all
Includes:
InternalComponent
Defined in:
lib/hyalite/text_component.rb

Instance Attribute Summary

Attributes included from InternalComponent

#mount_index

Instance Method Summary collapse

Methods included from InternalComponent

#recieve_component

Constructor Details

#initialize(text) ⇒ TextComponent

Returns a new instance of TextComponent.



7
8
9
# File 'lib/hyalite/text_component.rb', line 7

def initialize(text)
  @text = text
end

Instance Method Details

#current_elementObject



11
12
13
# File 'lib/hyalite/text_component.rb', line 11

def current_element
  @text
end

#mount_component(root_id, mount_ready, context) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/hyalite/text_component.rb', line 15

def mount_component(root_id, mount_ready, context)
  @root_node_id = root_id
  @native_node = $document.create_element('span').tap do |node|
    DOMPropertyOperations.set_attribute_for_id(node, root_id)
    Mount.node_id(node)
    node.text = @text
  end
end

#receive_component(next_text, mount_ready) ⇒ Object



29
30
31
32
33
34
# File 'lib/hyalite/text_component.rb', line 29

def receive_component(next_text, mount_ready)
  if next_text != @text
    @text = next_text
    node.text = @text
  end
end

#unmount_componentObject



24
25
26
27
# File 'lib/hyalite/text_component.rb', line 24

def unmount_component
  @native_node = nil
  Mount.purge_id(@root_node_id)
end