@superhero/eventflow-spoke 4.5.2 → 4.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/consume.js +21 -9
  2. package/index.js +1 -1
  3. package/package.json +1 -1
package/consume.js CHANGED
@@ -1,3 +1,5 @@
1
+ import Log from '@superhero/log'
2
+
1
3
  export function locate(locator)
2
4
  {
3
5
  const
@@ -32,6 +34,7 @@ export default class ConsumeService
32
34
  #locator
33
35
  #spoke
34
36
  #lookupConsumerMap = new Map
37
+ log = new Log({ label: '[EVENTFLOW:SPOKE:CONSUME]' })
35
38
 
36
39
  constructor(locator, spoke)
37
40
  {
@@ -59,11 +62,11 @@ export default class ConsumeService
59
62
 
60
63
  async #consumer(service, event)
61
64
  {
62
- const consumer = this.#lazyloadConsumerName(event.name)
65
+ const consumer = this.#lazyloadConsumer(service, event)
63
66
 
64
67
  try
65
68
  {
66
- await service[consumer](event)
69
+ await consumer(event)
67
70
  }
68
71
  catch(reason)
69
72
  {
@@ -93,16 +96,20 @@ export default class ConsumeService
93
96
  }
94
97
  }
95
98
 
96
- #lazyloadConsumerName(eventName)
99
+ #lazyloadConsumer(service, event)
97
100
  {
98
- if(this.#lookupConsumerMap.has(eventName))
101
+ const lookupKey = event.domain + '.' + event.name
102
+
103
+ if(false === this.#lookupConsumerMap.has(lookupKey))
99
104
  {
100
- return this.#lookupConsumerMap.get(eventName)
105
+ const consumerName = this.#composeConsumerName(event.name)
106
+ this.#lookupConsumerMap.set(lookupKey,
107
+ consumerName in service
108
+ ? service[consumerName].bind(service)
109
+ : this.#fallbackConsumerCallback.bind(this, service, consumerName))
101
110
  }
102
-
103
- const consumer = this.#composeConsumerName(eventName)
104
- this.#lookupConsumerMap.set(eventName, consumer)
105
- return consumer
111
+
112
+ return this.#lookupConsumerMap.get(lookupKey)
106
113
  }
107
114
 
108
115
  #composeConsumerName(eventName)
@@ -116,4 +123,9 @@ export default class ConsumeService
116
123
 
117
124
  return observerName
118
125
  }
126
+
127
+ #fallbackConsumerCallback(service, consumerName, event)
128
+ {
129
+ this.log.warn`consumer missing ${event.domain} › ${event.name} not found in service ${service.constructor.name} › ${consumerName}`
130
+ }
119
131
  }
package/index.js CHANGED
@@ -332,7 +332,7 @@ export default class Spoke
332
332
  {
333
333
  clearTimeout(timeoutId)
334
334
  await unsubscribe().catch(reject)
335
- accept(event)
335
+ accept(event.name)
336
336
  }
337
337
  }
338
338
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/eventflow-spoke",
3
- "version": "4.5.2",
3
+ "version": "4.5.4",
4
4
  "description": "Eventflow spoke is the client component in the eventflow ecosystem.",
5
5
  "keywords": [
6
6
  "eventflow",