Class: Teek::UI::ComponentHandle

Inherits:
Object
  • Object
show all
Defined in:
lib/teek/ui/component_handle.rb

Overview

A component's own public surface, returned by WidgetDSL#component - the disciplined way a parent reaches a child's named widgets without falling back to the flat, global ui[] index (which never sees into a component's scope at all - see WidgetDSL#[]). Wraps a (document, scope) pair and resolves names exactly the way ui[] already does from inside the component's own block, just usable from outside it - the parent addresses children through this facade, not through @document.find or a captured Node.

Instance Method Summary collapse

Constructor Details

#initialize(document, scope) ⇒ ComponentHandle

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ComponentHandle.



17
18
19
20
# File 'lib/teek/ui/component_handle.rb', line 17

def initialize(document, scope)
  @document = document
  @scope = scope
end

Instance Method Details

#handle(name) ⇒ Handle? Also known as: []

Returns nil if this component never declared name - same nil-on-miss convention as WidgetDSL#[].

Parameters:

  • name (Symbol)

Returns:

  • (Handle, nil)

    nil if this component never declared name - same nil-on-miss convention as WidgetDSL#[]



25
26
27
28
# File 'lib/teek/ui/component_handle.rb', line 25

def handle(name)
  node = @document.find(name, scope: @scope)
  node && Handle.new(node)
end