@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.
- package/consume.js +21 -9
- package/index.js +1 -1
- 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.#
|
|
65
|
+
const consumer = this.#lazyloadConsumer(service, event)
|
|
63
66
|
|
|
64
67
|
try
|
|
65
68
|
{
|
|
66
|
-
await
|
|
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
|
-
#
|
|
99
|
+
#lazyloadConsumer(service, event)
|
|
97
100
|
{
|
|
98
|
-
|
|
101
|
+
const lookupKey = event.domain + '.' + event.name
|
|
102
|
+
|
|
103
|
+
if(false === this.#lookupConsumerMap.has(lookupKey))
|
|
99
104
|
{
|
|
100
|
-
|
|
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
|
-
|
|
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