@lppedd/di-wise-neo 0.20.0 → 0.21.0
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/dist/cjs/index.d.ts +4 -2
- package/dist/cjs/index.js +32 -12
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +4 -2
- package/dist/es/index.mjs +32 -12
- package/dist/es/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/cjs/index.d.ts
CHANGED
|
@@ -627,11 +627,13 @@ interface Container {
|
|
|
627
627
|
* Disposes this container and all its cached values.
|
|
628
628
|
*
|
|
629
629
|
* Token values implementing a `Disposable` interface (e.g., objects with a `dispose()` function)
|
|
630
|
-
* are
|
|
630
|
+
* are also disposed. All disposals, whether synchronous or asynchronous, are returned as promises
|
|
631
|
+
* in an array. Callers may await these promises (e.g., using `Promise.allSettled()`) if they want
|
|
632
|
+
* to ensure that all async work has completed.
|
|
631
633
|
*
|
|
632
634
|
* Note that children containers are disposed first, in creation order.
|
|
633
635
|
*/
|
|
634
|
-
dispose():
|
|
636
|
+
dispose(): Promise<unknown>[];
|
|
635
637
|
}
|
|
636
638
|
/**
|
|
637
639
|
* Creates a new container.
|
package/dist/cjs/index.js
CHANGED
|
@@ -57,7 +57,7 @@ function getTokenName(token) {
|
|
|
57
57
|
}
|
|
58
58
|
function getFullTokenName([token, name]) {
|
|
59
59
|
const tokenName = token ? token.name || "<unnamed>" : "<undefined token>";
|
|
60
|
-
return name ? `${tokenName}["${name}"]` : tokenName;
|
|
60
|
+
return name !== undefined ? `${tokenName}["${name}"]` : tokenName;
|
|
61
61
|
}
|
|
62
62
|
function getCause(error) {
|
|
63
63
|
if (!error) {
|
|
@@ -544,8 +544,12 @@ class TokenRegistry {
|
|
|
544
544
|
return registrations;
|
|
545
545
|
}
|
|
546
546
|
deleteAll() {
|
|
547
|
-
const tokens =
|
|
548
|
-
|
|
547
|
+
const tokens = [
|
|
548
|
+
...this.myRegistrations.keys()
|
|
549
|
+
];
|
|
550
|
+
const registrations = [
|
|
551
|
+
...this.myRegistrations.values()
|
|
552
|
+
].flat();
|
|
549
553
|
this.myRegistrations.clear();
|
|
550
554
|
return [
|
|
551
555
|
tokens,
|
|
@@ -563,7 +567,9 @@ class TokenRegistry {
|
|
|
563
567
|
registration.valueRef = undefined;
|
|
564
568
|
}
|
|
565
569
|
}
|
|
566
|
-
return
|
|
570
|
+
return [
|
|
571
|
+
...values
|
|
572
|
+
];
|
|
567
573
|
}
|
|
568
574
|
getAllFromParent(token, name) {
|
|
569
575
|
let registrations = this.myRegistrations.get(token) || this.myParent?.getAllFromParent(token, name);
|
|
@@ -661,7 +667,9 @@ function isDisposable(value) {
|
|
|
661
667
|
values.add(valueRef.current);
|
|
662
668
|
}
|
|
663
669
|
}
|
|
664
|
-
return
|
|
670
|
+
return [
|
|
671
|
+
...values
|
|
672
|
+
];
|
|
665
673
|
}
|
|
666
674
|
resetRegistry() {
|
|
667
675
|
this.checkDisposed();
|
|
@@ -672,7 +680,9 @@ function isDisposable(value) {
|
|
|
672
680
|
values.add(valueRef.current);
|
|
673
681
|
}
|
|
674
682
|
}
|
|
675
|
-
return
|
|
683
|
+
return [
|
|
684
|
+
...values
|
|
685
|
+
];
|
|
676
686
|
}
|
|
677
687
|
isRegistered(token, name) {
|
|
678
688
|
this.checkDisposed();
|
|
@@ -701,7 +711,9 @@ function isDisposable(value) {
|
|
|
701
711
|
values.add(valueRef.current);
|
|
702
712
|
}
|
|
703
713
|
}
|
|
704
|
-
return
|
|
714
|
+
return [
|
|
715
|
+
...values
|
|
716
|
+
];
|
|
705
717
|
}
|
|
706
718
|
resolve(token, name) {
|
|
707
719
|
this.checkDisposed();
|
|
@@ -727,13 +739,14 @@ function isDisposable(value) {
|
|
|
727
739
|
}
|
|
728
740
|
dispose() {
|
|
729
741
|
if (this.myDisposed) {
|
|
730
|
-
return;
|
|
742
|
+
return [];
|
|
731
743
|
}
|
|
744
|
+
this.myDisposed = true;
|
|
745
|
+
const promises = [];
|
|
732
746
|
// Dispose children containers first
|
|
733
747
|
for (const child of this.myChildren){
|
|
734
|
-
child.dispose();
|
|
748
|
+
promises.push(...child.dispose());
|
|
735
749
|
}
|
|
736
|
-
this.myDisposed = true;
|
|
737
750
|
this.myChildren.clear();
|
|
738
751
|
this.myParent?.myChildren?.delete(this);
|
|
739
752
|
const [, registrations] = this.myTokenRegistry.deleteAll();
|
|
@@ -750,11 +763,18 @@ function isDisposable(value) {
|
|
|
750
763
|
}
|
|
751
764
|
for (const value of allValues){
|
|
752
765
|
if (isDisposable(value)) {
|
|
753
|
-
|
|
766
|
+
try {
|
|
767
|
+
promises.push(Promise.resolve(value.dispose()));
|
|
768
|
+
} catch (e) {
|
|
769
|
+
promises.push(Promise.reject(e));
|
|
770
|
+
}
|
|
754
771
|
}
|
|
755
772
|
}
|
|
756
|
-
this.notifyDisposeHooks(
|
|
773
|
+
this.notifyDisposeHooks([
|
|
774
|
+
...cacheValues
|
|
775
|
+
]);
|
|
757
776
|
this.myHookRegistry.clear();
|
|
777
|
+
return promises;
|
|
758
778
|
}
|
|
759
779
|
registerClass(Class) {
|
|
760
780
|
const metadata = getMetadata(Class);
|