@fozy-labs/rx-toolkit 0.4.14 → 0.4.15
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.
|
@@ -26,8 +26,8 @@ export function reduxDevtools(options = {}) {
|
|
|
26
26
|
state = applyState(keys, initState, state);
|
|
27
27
|
scheduler.schedule(createFn());
|
|
28
28
|
return (newState) => {
|
|
29
|
-
if (newState === '$
|
|
30
|
-
|
|
29
|
+
if (newState === '$COMPLETED' || newState === '$CLEANED') {
|
|
30
|
+
state = deleteState(keys, state);
|
|
31
31
|
clearFn();
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
@@ -51,3 +51,31 @@ function applyState(keys, newState, state) {
|
|
|
51
51
|
});
|
|
52
52
|
return acc;
|
|
53
53
|
}
|
|
54
|
+
// Идем по ключам и удалаем последний, если оставется пустой объект, удаляем его рекурсивно
|
|
55
|
+
function deleteState(keys, state) {
|
|
56
|
+
if (keys.length === 0)
|
|
57
|
+
return state;
|
|
58
|
+
const acc = { ...state };
|
|
59
|
+
// Рекурсивная функция для удаления с очисткой пустых объектов
|
|
60
|
+
const deleteRecursive = (obj, pathKeys, index) => {
|
|
61
|
+
const key = pathKeys[index];
|
|
62
|
+
if (!obj || !obj.hasOwnProperty(key)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if (index === pathKeys.length - 1) {
|
|
66
|
+
delete obj[key];
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
obj[key] = { ...obj[key] };
|
|
70
|
+
deleteRecursive(obj[key], pathKeys, index + 1);
|
|
71
|
+
// Если объект стал пустым, удаляем его
|
|
72
|
+
if (Object.keys(obj[key]).length === 0) {
|
|
73
|
+
delete obj[key];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
deleteRecursive(acc, keys, 0);
|
|
79
|
+
console.log('deleteState', keys, state, acc);
|
|
80
|
+
return acc;
|
|
81
|
+
}
|
|
@@ -3,6 +3,6 @@ import { Observable } from "rxjs";
|
|
|
3
3
|
export declare class SharedOptions {
|
|
4
4
|
static DEVTOOLS: DevtoolsLike | null;
|
|
5
5
|
static onQueryError: ((error: unknown) => void) | null;
|
|
6
|
-
static getScopeName: () => string | null;
|
|
7
|
-
static getScopeDestroyed$: () => Observable<void> | null;
|
|
6
|
+
static getScopeName: (() => string | null) | null;
|
|
7
|
+
static getScopeDestroyed$: (() => Observable<void> | null) | null;
|
|
8
8
|
}
|
|
@@ -3,7 +3,7 @@ import { SharedOptions } from "../../common/options/SharedOptions";
|
|
|
3
3
|
export class Effect {
|
|
4
4
|
_onComplete;
|
|
5
5
|
_subscriptions = [];
|
|
6
|
-
_scopeDestroyedSub = SharedOptions.getScopeDestroyed
|
|
6
|
+
_scopeDestroyedSub = SharedOptions.getScopeDestroyed$?.()?.subscribe(() => {
|
|
7
7
|
this.complete();
|
|
8
8
|
});
|
|
9
9
|
closed = false;
|
|
@@ -4,7 +4,7 @@ import { SharedOptions } from "../../common/options/SharedOptions";
|
|
|
4
4
|
export class Signal extends BehaviorSubject {
|
|
5
5
|
_stateDevtools;
|
|
6
6
|
_rang = 0;
|
|
7
|
-
_scopeDestroyedSub = SharedOptions.getScopeDestroyed
|
|
7
|
+
_scopeDestroyedSub = SharedOptions.getScopeDestroyed$?.()?.subscribe(() => {
|
|
8
8
|
this.complete();
|
|
9
9
|
});
|
|
10
10
|
constructor(initialValue, options) {
|
|
@@ -52,7 +52,7 @@ export class Signal extends BehaviorSubject {
|
|
|
52
52
|
return this.next(value);
|
|
53
53
|
}
|
|
54
54
|
complete() {
|
|
55
|
-
this._stateDevtools?.('$
|
|
55
|
+
this._stateDevtools?.('$COMPLETED');
|
|
56
56
|
this._scopeDestroyedSub?.unsubscribe();
|
|
57
57
|
super.complete();
|
|
58
58
|
}
|