Class: Dommy::MessageChannel
- Inherits:
-
Object
- Object
- Dommy::MessageChannel
- Defined in:
- lib/dommy/message_channel.rb
Overview
‘MessageChannel` — creates a pair of `MessagePort`s connected to each other. `port1.postMessage(x)` queues a microtask that fires a `message` event on `port2`, and vice versa.
Instance Attribute Summary collapse
-
#port1 ⇒ Object
readonly
Returns the value of attribute port1.
-
#port2 ⇒ Object
readonly
Returns the value of attribute port2.
Instance Method Summary collapse
- #__js_get__(key) ⇒ Object
-
#initialize(window) ⇒ MessageChannel
constructor
A new instance of MessageChannel.
Constructor Details
#initialize(window) ⇒ MessageChannel
Returns a new instance of MessageChannel.
12 13 14 15 16 17 |
# File 'lib/dommy/message_channel.rb', line 12 def initialize(window) @port1 = MessagePort.new(window) @port2 = MessagePort.new(window) @port1.__entangle__(@port2) @port2.__entangle__(@port1) end |
Instance Attribute Details
#port1 ⇒ Object (readonly)
Returns the value of attribute port1.
10 11 12 |
# File 'lib/dommy/message_channel.rb', line 10 def port1 @port1 end |
#port2 ⇒ Object (readonly)
Returns the value of attribute port2.
10 11 12 |
# File 'lib/dommy/message_channel.rb', line 10 def port2 @port2 end |
Instance Method Details
#__js_get__(key) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/dommy/message_channel.rb', line 19 def __js_get__(key) case key when "port1" @port1 when "port2" @port2 end end |