Class: Live::Element
- Inherits:
-
Object
- Object
- Live::Element
- Defined in:
- lib/live/element.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #bind(page) ⇒ Object
- #forward(details = nil) ⇒ Object
- #handle(event, details) ⇒ Object
-
#initialize(id, **data) ⇒ Element
constructor
A new instance of Element.
- #rpc(method, arguments) ⇒ Object
Constructor Details
#initialize(id, **data) ⇒ Element
Returns a new instance of Element.
27 28 29 30 31 32 33 |
# File 'lib/live/element.rb', line 27 def initialize(id, **data) @id = id @data = data @data[:class] ||= self.class.name @page = nil end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
35 36 37 |
# File 'lib/live/element.rb', line 35 def id @id end |
Instance Method Details
#bind(page) ⇒ Object
45 46 47 |
# File 'lib/live/element.rb', line 45 def bind(page) @page = page end |
#forward(details = nil) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/live/element.rb', line 37 def forward(details = nil) if details "live.forward(#{JSON.dump(@id)}, event, #{JSON.dump(details)})" else "live.forward(#{JSON.dump(@id)}, event)" end end |
#handle(event, details) ⇒ Object
49 50 |
# File 'lib/live/element.rb', line 49 def handle(event, details) end |
#rpc(method, arguments) ⇒ Object
52 53 54 55 |
# File 'lib/live/element.rb', line 52 def rpc(method, arguments) # This update might not be sent right away. Therefore, mutable arguments may be serialized to JSON at a later time (or never). This could be a race condition: @page.updates.enqueue([method, arguments]) end |