Class: Interfacets::Test::Js::NodoBus

Inherits:
Nodo::Core
  • Object
show all
Defined in:
lib/interfacets/test/js/nodo_bus.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver_index:, client_system_json:) ⇒ NodoBus

Returns a new instance of NodoBus.



8
9
10
11
12
# File 'lib/interfacets/test/js/nodo_bus.rb', line 8

def initialize(receiver_index:, client_system_json:)
  super()
  @receiver_index = receiver_index
  @client_system_json = client_system_json
end

Instance Attribute Details

#client_system_json ⇒ Object (readonly)

Returns the value of attribute client_system_json.



7
8
9
# File 'lib/interfacets/test/js/nodo_bus.rb', line 7

def client_system_json
  @client_system_json
end

#receiver_index ⇒ Object (readonly)

Returns the value of attribute receiver_index.



7
8
9
# File 'lib/interfacets/test/js/nodo_bus.rb', line 7

def receiver_index
  @receiver_index
end

Instance Method Details

#dispatch(channel_id, event) ⇒ Object



14
15
16
17
# File 'lib/interfacets/test/js/nodo_bus.rb', line 14

def dispatch(channel_id, event)
  js_dispatch(channel_id, event)
  render
end

#handler(channel_id) ⇒ Object



19
20
21
# File 'lib/interfacets/test/js/nodo_bus.rb', line 19

def handler(channel_id)
  receiver_index.fetch(channel_id).handler
end

#init(hydrated_facet:) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/interfacets/test/js/nodo_bus.rb', line 23

def init(hydrated_facet:)
  js_init(
    clientSystemJson: client_system_json,
    hydratedFacet: hydrated_facet
  )
  render
end

#render ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/interfacets/test/js/nodo_bus.rb', line 31

def render
  receiver_index.each do |id, ch|
    state = js_get_state(id)
    next if state.nil?

    ch.receive(
      payload: state.fetch("data"),
      dispatch: ->(e) { dispatch(id, e) }
    )

    receiver_index.each do |id, ch|
      if ch.respond_to?(:response_queue)
        ch.flush_responses.each do |response|
          dispatch(id, response)
        end
      end
    end
  end

  if js_get_logs.any? { _1.fetch("type") == "error" }
    js_get_logs
    .map { _1.fetch("value") }
    .then { raise(_1.join("\n")) }
  end
end