Class: Hokusai::Mounting::MountEntry

Inherits:
Object
  • Object
show all
Defined in:
ui/src/hokusai/mounting/mount_entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, ast, block, parent, target = parent, context: nil) ⇒ MountEntry

Returns a new instance of MountEntry.



6
7
8
9
10
11
12
13
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 6

def initialize(index, ast, block, parent, target = parent, context: nil)
  @index = index
  @ast = ast
  @block = block
  @parent = parent
  @target = target
  @ctx = context
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



4
5
6
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 4

def ast
  @ast
end

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 4

def block
  @block
end

#ctxObject (readonly)

Returns the value of attribute ctx.



4
5
6
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 4

def ctx
  @ctx
end

#indexObject (readonly)

Returns the value of attribute index.



4
5
6
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 4

def index
  @index
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 4

def parent
  @parent
end

#targetObject (readonly)

Returns the value of attribute target.



4
5
6
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 4

def target
  @target
end

Instance Method Details

#debugObject



27
28
29
30
31
32
33
34
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 27

def debug
  StringIO.open do |io|
    io << "#{block.class} | #{ast.type} (#{index})\n"
    io << "#{block.node.ast.children.map(&:type)}"
    io << "parent: #{parent.class}\n"
    io << "target: #{target.class}\n\n"
  end.string
end

#loop?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 15

def loop?
  ast.loop?
end

#mount(context: nil) {|child_block| ... } ⇒ Object

Yields:

  • (child_block)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 41

def mount(context: nil)
  klass = target.class.use(ast.type)
  portal = Node.new(ast)

  node = klass.compile(ast.type, portal)
  node.add_styles(target.class)
  node.add_props_from_block(target, context: context || ctx)

  child_block = klass.new(node: node)
  child_block.node.meta.publisher.add(target) # todo
  UpdateEntry.new(child_block, block, target).register(context: context || ctx)

  block.class.provides.each do |k, v|
    if v.is_a?(Symbol)
      Node.provide(child_block.node, k, ->{ block.public_send(v) })

      # child_block.node.meta.provides[k] = -> { block.public_send(v) }
      # child_block.class.provides[k] = -> { block.public_send(v) }
    else
      Node.provide(child_block.node, k, v)
      # child_block.node.meta.provides[k] = v
      # child_block.class.provides[k] = v
    end
  end

  block.node.meta << child_block

  yield child_block

  block.public_send(:on_mounted) if block.respond_to?(:on_mounted)
end

#slot?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 23

def slot?
  ast.slot?
end

#virtual?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 19

def virtual?
  ast.virtual?
end

#with_block(new_block, supercede_parent: false) ⇒ Object



36
37
38
39
# File 'ui/src/hokusai/mounting/mount_entry.rb', line 36

def with_block(new_block, supercede_parent: false)
  parent_block = supercede_parent ? block : parent
  MountEntry.new(index, ast, new_block, parent_block, target, context: ctx)
end