@dereekb/dbx-core 13.0.4 → 13.0.6
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.
|
@@ -19,6 +19,15 @@ import { formatDate } from '@angular/common';
|
|
|
19
19
|
* when the DestroyRef is destroyed in the context.
|
|
20
20
|
*
|
|
21
21
|
* Must be run in an Angular injection context.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Clean up a Destroyable object (e.g., SubscriptionObject, LockSet):
|
|
25
|
+
* const sub = new SubscriptionObject(obs$.subscribe(handler));
|
|
26
|
+
* clean(sub);
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Clean up a destroy function directly:
|
|
30
|
+
* clean(() => resource.release());
|
|
22
31
|
*/
|
|
23
32
|
function clean(input) {
|
|
24
33
|
const destroyRef = inject(DestroyRef);
|
|
@@ -35,6 +44,14 @@ function clean(input) {
|
|
|
35
44
|
* when the DestroyRef is destroyed in the context.
|
|
36
45
|
*
|
|
37
46
|
* Must be run in an Angular injection context.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // Complete a BehaviorSubject when the component is destroyed:
|
|
50
|
+
* readonly value$ = completeOnDestroy(new BehaviorSubject<string>('initial'));
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Complete a ReplaySubject when the component is destroyed:
|
|
54
|
+
* readonly events$ = completeOnDestroy(new ReplaySubject<Event>(1));
|
|
38
55
|
*/
|
|
39
56
|
function completeOnDestroy(input) {
|
|
40
57
|
clean(() => input.complete());
|
|
@@ -46,6 +63,14 @@ function completeOnDestroy(input) {
|
|
|
46
63
|
* Creates a new SubscriptionObject that is automatically destroyed when the context is destroyed.
|
|
47
64
|
*
|
|
48
65
|
* Must be run within an Angular injection context.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // Pass a subscription directly - it will be cleaned up automatically:
|
|
69
|
+
* cleanSubscription(obs$.subscribe(handler));
|
|
70
|
+
*
|
|
71
|
+
* // Or create first, then set the subscription later:
|
|
72
|
+
* readonly _sub = cleanSubscription();
|
|
73
|
+
* this._sub.subscription = obs$.subscribe(handler);
|
|
49
74
|
*/
|
|
50
75
|
function cleanSubscription(sub) {
|
|
51
76
|
const subscription = getValueFromGetter(sub);
|
|
@@ -59,7 +84,17 @@ function cleanSubscription(sub) {
|
|
|
59
84
|
*
|
|
60
85
|
* Must be run within an Angular injection context.
|
|
61
86
|
*
|
|
62
|
-
* @param
|
|
87
|
+
* @param config Optional configuration for destruction behavior and callbacks.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* // Create a simple lockset:
|
|
91
|
+
* readonly lockSet = cleanLockSet();
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* // Create with a callback when the lockset is destroyed:
|
|
95
|
+
* readonly lockSet = cleanLockSet({
|
|
96
|
+
* onLockSetDestroy: () => console.log('lockset destroyed')
|
|
97
|
+
* });
|
|
63
98
|
*/
|
|
64
99
|
function cleanLockSet(config) {
|
|
65
100
|
const { onDestroy, onLockSetDestroy, destroyLocksetTiming } = config ?? {};
|
|
@@ -87,6 +122,10 @@ function cleanLockSet(config) {
|
|
|
87
122
|
*
|
|
88
123
|
* @param lockSet The lockset to use.
|
|
89
124
|
* @param onDestroy The function to run when the lockset is unlocked.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* // Defer cleanup until the lockset unlocks after component destroy:
|
|
128
|
+
* cleanWithLockSet(this.lockSet, () => resource.release());
|
|
90
129
|
*/
|
|
91
130
|
function cleanWithLockSet(lockSet, onDestroy) {
|
|
92
131
|
const destroyRef = inject(DestroyRef);
|
|
@@ -100,6 +139,18 @@ function cleanWithLockSet(lockSet, onDestroy) {
|
|
|
100
139
|
* Creates a new SubscriptionObject that is automatically destroyed when the context is destroyed, and the lock set's next unlock occurs.
|
|
101
140
|
*
|
|
102
141
|
* Must be run within an Angular injection context.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* // Pass a subscription that waits for the lockset to unlock before cleanup:
|
|
145
|
+
* readonly _sub = cleanSubscriptionWithLockSet({
|
|
146
|
+
* lockSet: this.lockSet,
|
|
147
|
+
* sub: obs$.subscribe(handler)
|
|
148
|
+
* });
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* // Create first, then set the subscription later:
|
|
152
|
+
* readonly _sub = cleanSubscriptionWithLockSet({ lockSet: this.lockSet });
|
|
153
|
+
* this._sub.subscription = obs$.subscribe(handler);
|
|
103
154
|
*/
|
|
104
155
|
function cleanSubscriptionWithLockSet(input) {
|
|
105
156
|
const subscription = getValueFromGetter(input.sub);
|
|
@@ -112,6 +163,15 @@ function cleanSubscriptionWithLockSet(input) {
|
|
|
112
163
|
* Creates a new LoadingStateContext that is automatically destroyed when the context is destroyed.
|
|
113
164
|
*
|
|
114
165
|
* Must be run within an Angular injection context.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* // Create with an observable source:
|
|
169
|
+
* readonly context = cleanLoadingContext<MyData>(this.data$);
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* // Create empty, then set the observable source later:
|
|
173
|
+
* readonly context = cleanLoadingContext<MyData>();
|
|
174
|
+
* this.context.obs = this.data$;
|
|
115
175
|
*/
|
|
116
176
|
function cleanLoadingContext(input) {
|
|
117
177
|
return clean(loadingStateContext(input));
|
|
@@ -120,6 +180,15 @@ function cleanLoadingContext(input) {
|
|
|
120
180
|
* Creates a new ListLoadingStateContext that is automatically destroyed when the context is destroyed.
|
|
121
181
|
*
|
|
122
182
|
* Must be run within an Angular injection context.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* // Create with an observable source:
|
|
186
|
+
* readonly listContext = cleanListLoadingContext<MyItem>(this.items$);
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* // Create empty, then set the observable source later:
|
|
190
|
+
* readonly listContext = cleanListLoadingContext<MyItem>();
|
|
191
|
+
* this.listContext.obs = this.items$;
|
|
123
192
|
*/
|
|
124
193
|
function cleanListLoadingContext(input) {
|
|
125
194
|
return clean(listLoadingStateContext(input));
|
|
@@ -129,6 +198,15 @@ function cleanListLoadingContext(input) {
|
|
|
129
198
|
* Creates a new DestroyFunctionObject that is automatically destroyed when the context is destroyed.
|
|
130
199
|
*
|
|
131
200
|
* Must be run within an Angular injection context.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* // Pass a destroy function directly:
|
|
204
|
+
* cleanDestroy(() => resource.release());
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* // Create first, then set the destroy function later:
|
|
208
|
+
* readonly _destroy = cleanDestroy();
|
|
209
|
+
* this._destroy.setDestroyFunction(() => resource.release());
|
|
132
210
|
*/
|
|
133
211
|
function cleanDestroy(input) {
|
|
134
212
|
const destroyFunction = new DestroyFunctionObject(input);
|