@superhero/eventflow-spoke 4.5.6 → 4.5.7

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 (2) hide show
  1. package/index.js +26 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -262,6 +262,26 @@ export default class Spoke
262
262
  this.log.info`consuming: ${domain} › ${name}`
263
263
  }
264
264
 
265
+ removeConsumer(domain, name, callback)
266
+ {
267
+ this.consumers[domain].off(name, callback)
268
+
269
+ // If there are no listeners for the domain and name
270
+ // then broadcast an unsubscribe message.
271
+ if(0 === this.subscriptions[domain].listenerCount(name)
272
+ && 0 === this.consumers [domain].listenerCount(name))
273
+ {
274
+ this.#broadcast('unsubscribe', domain, name)
275
+ }
276
+
277
+ // If there are no consumers attached to the domain
278
+ // by any name, then delete the domain.
279
+ if(0 === this.consumers[domain].listenerCount())
280
+ {
281
+ delete this.consumers[domain]
282
+ }
283
+ }
284
+
265
285
  subscribe(domain, name, callback)
266
286
  {
267
287
  this.subscriptions[domain].on(name, callback)
@@ -279,8 +299,13 @@ export default class Spoke
279
299
  && 0 === this.consumers [domain].listenerCount(name))
280
300
  {
281
301
  this.#broadcast('unsubscribe', domain, name)
302
+ }
303
+
304
+ // If there are no subscriptions attached to the domain
305
+ // by any name, then delete the domain.
306
+ if(0 === this.subscriptions[domain].listenerCount())
307
+ {
282
308
  delete this.subscriptions[domain]
283
- delete this.consumers [domain]
284
309
  }
285
310
  }
286
311
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/eventflow-spoke",
3
- "version": "4.5.6",
3
+ "version": "4.5.7",
4
4
  "description": "Eventflow spoke is the client component in the eventflow ecosystem.",
5
5
  "keywords": [
6
6
  "eventflow",