Class: Async::Debug::ReactorView
- Inherits:
-
Live::View
- Object
- Live::View
- Async::Debug::ReactorView
- Defined in:
- lib/async/debug/reactor_view.rb
Instance Method Summary collapse
- #bind(page) ⇒ Object
- #close ⇒ Object
- #handle(event, details) ⇒ Object
-
#initialize ⇒ ReactorView
constructor
A new instance of ReactorView.
- #render(builder) ⇒ Object
- #render_node(builder, node = @root) ⇒ Object
Constructor Details
#initialize ⇒ ReactorView
Returns a new instance of ReactorView.
11 12 13 14 15 16 |
# File 'lib/async/debug/reactor_view.rb', line 11 def initialize(...) super @update = nil @root = Async::Task.current.root end |
Instance Method Details
#bind(page) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/async/debug/reactor_view.rb', line 18 def bind(page) super(page) @update = Async do |task| while true task.sleep(1.0/10.0) self.update! end end end |
#close ⇒ Object
29 30 31 32 33 |
# File 'lib/async/debug/reactor_view.rb', line 29 def close @update.stop super end |
#handle(event, details) ⇒ Object
35 36 37 |
# File 'lib/async/debug/reactor_view.rb', line 35 def handle(event, details) update! end |
#render(builder) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/async/debug/reactor_view.rb', line 73 def render(builder) builder.tag :div, class: 'tree' do builder.tag :ul do builder.inline :li do render_node(builder) end end end end |
#render_node(builder, node = @root) ⇒ Object
39 40 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 'lib/async/debug/reactor_view.rb', line 39 def render_node(builder, node = @root) klass = [] title = [] if node.respond_to?(:status) klass << node.status end if node.transient? klass << "transient" end if node.respond_to?(:backtrace) if backtrace = node.backtrace title = backtrace.first(8) end end builder.inline :span, class: klass.join(' '), title: title.join("\n") do text = node.annotation || "#{node.class} 0x#{node.object_id.to_s(16)}" builder.text(text) end if node.children builder.tag :ul do node.children.each do |child| builder.inline :li do render_node(builder, child) end end end end end |