Class: Dommy::MessageChannel

Inherits:
Object
  • Object
show all
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.

Spec: html.spec.whatwg.org/multipage/web-messaging.html

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#port1Object (readonly)

Returns the value of attribute port1.



10
11
12
# File 'lib/dommy/message_channel.rb', line 10

def port1
  @port1
end

#port2Object (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