Class: Live::Page
- Inherits:
-
Object
- Object
- Live::Page
- Defined in:
- lib/live/page.rb
Instance Attribute Summary collapse
-
#updates ⇒ Object
readonly
Returns the value of attribute updates.
Instance Method Summary collapse
- #bind(element) ⇒ Object
- #handle(id, event, details) ⇒ Object
-
#initialize(resolver) ⇒ Page
constructor
A new instance of Page.
- #resolve(id, data) ⇒ Object
- #run(connection) ⇒ Object
Constructor Details
#initialize(resolver) ⇒ Page
Returns a new instance of Page.
31 32 33 34 35 36 |
# File 'lib/live/page.rb', line 31 def initialize(resolver) @resolver = resolver @elements = {} @updates = Async::Queue.new end |
Instance Attribute Details
#updates ⇒ Object (readonly)
Returns the value of attribute updates.
38 39 40 |
# File 'lib/live/page.rb', line 38 def updates @updates end |
Instance Method Details
#bind(element) ⇒ Object
40 41 42 43 44 |
# File 'lib/live/page.rb', line 40 def bind(element) @elements[element.id] = element element.bind(self) end |
#handle(id, event, details) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/live/page.rb', line 50 def handle(id, event, details) if element = @elements[id] return element.handle(event, details) else Console.logger.warn(self, "Could not handle event:", event, details) end return nil end |
#resolve(id, data) ⇒ Object
46 47 48 |
# File 'lib/live/page.rb', line 46 def resolve(id, data) @resolver.call(id, data) end |
#run(connection) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/live/page.rb', line 60 def run(connection) reader_task = start_reader(connection) while update = @updates.dequeue Console.logger.debug(self, "Sending update:", update) connection.write(update) connection.flush if @updates.empty? end ensure reader_task&.stop end |