@foblex/flow 19.1.3 → 19.1.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.
@@ -370,7 +370,13 @@ class FChannelHub {
370
370
  return result;
371
371
  }
372
372
  listen(destroyRef, callback) {
373
- let current = callback;
373
+ let tornDown = false;
374
+ let current = () => {
375
+ if (tornDown || destroyRef.destroyed) {
376
+ return;
377
+ }
378
+ callback();
379
+ };
374
380
  const cleanups = [];
375
381
  const onSubscribes = [];
376
382
  const teardownSetters = [];
@@ -384,9 +390,8 @@ class FChannelHub {
384
390
  if (res.setTeardown)
385
391
  teardownSetters.push(res.setTeardown);
386
392
  }
387
- const unsubs = this._channels.map((ch) => ch.listen(() => current()));
393
+ const unsubs = [];
388
394
  let unregisterOnDestroy = null;
389
- let tornDown = false;
390
395
  const teardown = () => {
391
396
  if (tornDown)
392
397
  return;
@@ -400,11 +405,31 @@ class FChannelHub {
400
405
  .slice()
401
406
  .reverse()
402
407
  .forEach((set) => set(teardown));
408
+ if (destroyRef.destroyed) {
409
+ teardown();
410
+ return;
411
+ }
412
+ this._channels.forEach((channel) => {
413
+ unsubs.push(channel.listen(() => {
414
+ if (tornDown || destroyRef.destroyed) {
415
+ return;
416
+ }
417
+ current();
418
+ }));
419
+ });
420
+ if (destroyRef.destroyed) {
421
+ teardown();
422
+ return;
423
+ }
424
+ unregisterOnDestroy = destroyRef.onDestroy(teardown);
403
425
  onSubscribes
404
426
  .slice()
405
427
  .reverse()
406
- .forEach((fn) => fn(current));
407
- unregisterOnDestroy = destroyRef.onDestroy(teardown);
428
+ .forEach((fn) => {
429
+ if (!tornDown && !destroyRef.destroyed) {
430
+ fn(current);
431
+ }
432
+ });
408
433
  }
409
434
  }
410
435