Class: Hyalite::DOMComponent

Inherits:
Object
  • Object
show all
Includes:
InternalComponent, MultiChildren
Defined in:
lib/hyalite/dom_component.rb

Instance Attribute Summary collapse

Attributes included from InternalComponent

#mount_index

Instance Method Summary collapse

Methods included from InternalComponent

#recieve_component

Methods included from MultiChildren

clear_queue, insert_child_at, #instantiate_children, markup_queue, #mount_children, #move_child, process_children_updates, process_queue, process_updates, #remove_child, #unmount_child, #unmount_children, #update_children, update_depth, update_depth=, update_queue, #update_text_content, wrap_update

Constructor Details

#initialize(element) ⇒ DOMComponent

Returns a new instance of DOMComponent.



13
14
15
16
17
# File 'lib/hyalite/dom_component.rb', line 13

def initialize(element)
  @element = element
  @tag = @element.type.downcase
  @input_wrapper = InputWrapper.new(self)
end

Instance Attribute Details

#root_node_idObject (readonly)

Returns the value of attribute root_node_id.



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

def root_node_id
  @root_node_id
end

Instance Method Details

#current_elementObject



19
20
21
# File 'lib/hyalite/dom_component.rb', line 19

def current_element
  @element
end

#mount_component(root_id, mount_ready, context) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hyalite/dom_component.rb', line 23

def mount_component(root_id, mount_ready, context)
  return if @tag == "noscript"
  @root_node_id = root_id

  props = current_element.props

  case @tag
  # when 'iframe', 'img', 'form', 'video', 'audio'
  #   this._wrapperState = {
  #     listeners: null,
  #   }
  #   transaction.getReactMountReady().enqueue(trapBubbledEventsLocal, this);
  # when 'button'
  #   props = ReactDOMButton.getNativeProps(this, props, nativeParent);
  when 'input'
    @input_wrapper.mount_wrapper
    props = @input_wrapper.native_props
  # when 'option'
  #   ReactDOMOption.mountWrapper(this, props, nativeParent);
  #   props = ReactDOMOption.getNativeProps(this, props);
  # when 'select'
  #   ReactDOMSelect.mountWrapper(this, props, nativeParent);
  #   props = ReactDOMSelect.getNativeProps(this, props);
  #   transaction.getReactMountReady().enqueue(trapBubbledEventsLocal, this);
  # when 'textarea'
  #   ReactDOMTextarea.mountWrapper(this, props, nativeParent);
  #   props = ReactDOMTextarea.getNativeProps(this, props);
  #   transaction.getReactMountReady().enqueue(trapBubbledEventsLocal, this);
  end

  markup = create_open_tag_markup_and_put_listeners(mount_ready, @element.props)
  create_content_markup(mount_ready, markup, context)
end

#public_instanceObject



125
126
127
# File 'lib/hyalite/dom_component.rb', line 125

def public_instance
  native_node
end

#receive_component(next_element, mount_ready, context) ⇒ Object



82
83
84
85
86
# File 'lib/hyalite/dom_component.rb', line 82

def receive_component(next_element, mount_ready, context)
  prev_element = @element
  @element = next_element
  update_component(mount_ready, prev_element, next_element, context);
end

#to_sObject



129
130
131
132
133
134
135
# File 'lib/hyalite/dom_component.rb', line 129

def to_s
  {
    tag: @tag,
    root_node_id: root_node_id,
    rendered_children: @rendered_children,
  }.to_s
end

#unmount_componentObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/hyalite/dom_component.rb', line 57

def unmount_component
  case @tag
  # when 'iframe', 'img', 'form'
  #   listeners = this._wrapperState.listeners;
  #   if (listeners) {
  #     for (var i = 0; i < listeners.length; i++) {
  #       listeners[i].remove();
  #     }
  #   }
  when 'input'
    @input_wrapper.unmount_wrapper
  end

  unmount_children
  BrowserEvent.delete_all_listeners(@root_node_id)
  Mount.purge_id(@root_node_id)
  @root_node_id = nil
  # @wrapper_state = null;
  if @node_with_legacy_properties
    node = @node_with_legacy_properties
    node.internal_component = nil
    @node_with_legacy_properties = nil
  end
end

#update_component(mount_ready, prev_element, next_element, context) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/hyalite/dom_component.rb', line 88

def update_component(mount_ready, prev_element, next_element, context)
  last_props = prev_element.props
  next_props = @element.props

  case @tag
  # when 'button':
  #   lastProps = ReactDOMButton.getNativeProps(this, lastProps);
  #   nextProps = ReactDOMButton.getNativeProps(this, nextProps);
  when 'input'
    @input_wrapper.update_wrapper
    last_props = @input_wrapper.native_props(last_props)
  #   nextProps = ReactDOMInput.getNativeProps(this, nextProps);
  # when 'option':
  #   lastProps = ReactDOMOption.getNativeProps(this, lastProps);
  #   nextProps = ReactDOMOption.getNativeProps(this, nextProps);
  # when 'select':
  #   lastProps = ReactDOMSelect.getNativeProps(this, lastProps);
  #   nextProps = ReactDOMSelect.getNativeProps(this, nextProps);
  # when 'textarea':
  #   ReactDOMTextarea.updateWrapper(this);
  #   lastProps = ReactDOMTextarea.getNativeProps(this, lastProps);
  #   nextProps = ReactDOMTextarea.getNativeProps(this, nextProps);
  end

  # assertValidProps(this, nextProps);
  update_dom_properties(last_props, next_props, mount_ready)
  update_dom_children(last_props, next_props, mount_ready, context)

  # if (!canDefineProperty && this._nodeWithLegacyProperties) {
  #   this._nodeWithLegacyProperties.props = nextProps;
  # }

  if @tag == 'select'
    mount_ready.enqueue { post_update_select_wrapper }
  end
end