Class: Hyalite::CompositeComponent
- Includes:
- InternalComponent
- Defined in:
- lib/hyalite/composite_component.rb
Instance Attribute Summary collapse
-
#current_element ⇒ Object
readonly
Returns the value of attribute current_element.
-
#mount_order ⇒ Object
Returns the value of attribute mount_order.
-
#pending_callbacks ⇒ Object
Returns the value of attribute pending_callbacks.
-
#pending_element ⇒ Object
Returns the value of attribute pending_element.
-
#pending_force_update ⇒ Object
Returns the value of attribute pending_force_update.
-
#pending_state_queue ⇒ Object
Returns the value of attribute pending_state_queue.
-
#rendered_component ⇒ Object
readonly
Returns the value of attribute rendered_component.
-
#top_level_wrapper ⇒ Object
Returns the value of attribute top_level_wrapper.
Attributes included from InternalComponent
Class Method Summary collapse
Instance Method Summary collapse
- #attach_ref(ref, component) ⇒ Object
-
#initialize(element) ⇒ CompositeComponent
constructor
A new instance of CompositeComponent.
- #inspect ⇒ Object
- #mount_component(root_id, mount_ready, context) ⇒ Object
- #perform_update_if_necessary(mount_ready) ⇒ Object
- #public_instance ⇒ Object
- #unmount_component ⇒ Object
Methods included from InternalComponent
Constructor Details
#initialize(element) ⇒ CompositeComponent
Returns a new instance of CompositeComponent.
18 19 20 21 |
# File 'lib/hyalite/composite_component.rb', line 18 def initialize(element) @element = element @current_element = @element end |
Instance Attribute Details
#current_element ⇒ Object (readonly)
Returns the value of attribute current_element.
9 10 11 |
# File 'lib/hyalite/composite_component.rb', line 9 def current_element @current_element end |
#mount_order ⇒ Object
Returns the value of attribute mount_order.
10 11 12 |
# File 'lib/hyalite/composite_component.rb', line 10 def mount_order @mount_order end |
#pending_callbacks ⇒ Object
Returns the value of attribute pending_callbacks.
10 11 12 |
# File 'lib/hyalite/composite_component.rb', line 10 def pending_callbacks @pending_callbacks end |
#pending_element ⇒ Object
Returns the value of attribute pending_element.
10 11 12 |
# File 'lib/hyalite/composite_component.rb', line 10 def pending_element @pending_element end |
#pending_force_update ⇒ Object
Returns the value of attribute pending_force_update.
10 11 12 |
# File 'lib/hyalite/composite_component.rb', line 10 def pending_force_update @pending_force_update end |
#pending_state_queue ⇒ Object
Returns the value of attribute pending_state_queue.
10 11 12 |
# File 'lib/hyalite/composite_component.rb', line 10 def pending_state_queue @pending_state_queue end |
#rendered_component ⇒ Object (readonly)
Returns the value of attribute rendered_component.
9 10 11 |
# File 'lib/hyalite/composite_component.rb', line 9 def rendered_component @rendered_component end |
#top_level_wrapper ⇒ Object
Returns the value of attribute top_level_wrapper.
10 11 12 |
# File 'lib/hyalite/composite_component.rb', line 10 def top_level_wrapper @top_level_wrapper end |
Class Method Details
.next_mount_id ⇒ Object
14 15 16 |
# File 'lib/hyalite/composite_component.rb', line 14 def self.next_mount_id @next_mount_id += 1 end |
Instance Method Details
#attach_ref(ref, component) ⇒ Object
100 101 102 103 |
# File 'lib/hyalite/composite_component.rb', line 100 def attach_ref(ref, component) @instance.refs ||= {} @instance.refs[ref] = component.public_instance end |
#inspect ⇒ Object
96 97 98 |
# File 'lib/hyalite/composite_component.rb', line 96 def inspect "CompositeComponent: instance: #{@instance.inspect}" 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 |
# File 'lib/hyalite/composite_component.rb', line 23 def mount_component(root_id, mount_ready, context) @context = context @mount_order = CompositeComponent.next_mount_id @root_node_id = root_id @instance = @current_element.type.new @instance.init_component(@current_element.props, @context, UpdateQueue) Hyalite.instance_map[@instance] = self @pending_state_queue = nil @pending_replace_state = false @pending_force_update = false @instance.component_will_mount if @pending_state_queue @instance.state = process_pending_state(@instance.props, @instance.context) end @rendered_component = Hyalite.instantiate_component(render_component(@instance)) markup = Reconciler.mount_component( @rendered_component, root_id, mount_ready, context.merge(@instance.child_context) ) mount_ready.enqueue { @instance.component_did_mount } markup end |
#perform_update_if_necessary(mount_ready) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/hyalite/composite_component.rb', line 77 def perform_update_if_necessary(mount_ready) if @pending_element receive_component(@pending_element, mount_ready, @context) end if (@pending_state_queue && @pending_state_queue.any?) || @pending_force_update update_component( mount_ready, @current_element, @current_element, @context, @context) end end |
#public_instance ⇒ Object
92 93 94 |
# File 'lib/hyalite/composite_component.rb', line 92 def public_instance @instance end |
#unmount_component ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hyalite/composite_component.rb', line 56 def unmount_component @instance.component_will_unmount Reconciler.unmount_component(@rendered_component) @rendered_component = nil @instance = nil @pending_state_queue = nil @pending_replace_state = false @pending_force_update = false @pending_callbacks = nil @pending_element = nil @context = nil @root_node_id = nil @top_level_wrapper = nil Hyalite.instance_map.delete(@instance) end |