@fozy-labs/rx-toolkit 0.4.13 → 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.
- package/dist/common/devtools/reduxDevtools.js +30 -2
- package/dist/common/options/SharedOptions.d.ts +2 -2
- package/dist/common/options/SharedOptions.js +2 -2
- package/dist/query/core/Resource/ResourceAgent.d.ts +2 -0
- package/dist/query/core/Resource/ResourceAgent.js +2 -0
- package/dist/query/types/Resource.types.d.ts +3 -1
- package/dist/signals/signals/Effect.d.ts +1 -0
- package/dist/signals/signals/Effect.js +5 -0
- package/dist/signals/signals/Signal.d.ts +1 -0
- package/dist/signals/signals/Signal.js +6 -1
- package/package.json +1 -1
|
@@ -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
|
}
|
|
@@ -7,6 +7,7 @@ export declare class ResourceAgent<D extends ResourceDefinition> implements Reso
|
|
|
7
7
|
state$: Computed<{
|
|
8
8
|
isInitiated: boolean;
|
|
9
9
|
isLoading: boolean;
|
|
10
|
+
isInitialLoading: boolean;
|
|
10
11
|
isDone: boolean;
|
|
11
12
|
isSuccess: boolean;
|
|
12
13
|
isError: boolean;
|
|
@@ -18,6 +19,7 @@ export declare class ResourceAgent<D extends ResourceDefinition> implements Reso
|
|
|
18
19
|
} | {
|
|
19
20
|
isInitiated: boolean;
|
|
20
21
|
isLoading: boolean;
|
|
22
|
+
isInitialLoading: boolean;
|
|
21
23
|
isDone: boolean;
|
|
22
24
|
isSuccess: boolean;
|
|
23
25
|
isError: boolean;
|
|
@@ -17,6 +17,7 @@ export class ResourceAgent {
|
|
|
17
17
|
return {
|
|
18
18
|
isInitiated: false,
|
|
19
19
|
isLoading: false,
|
|
20
|
+
isInitialLoading: false,
|
|
20
21
|
isDone: false,
|
|
21
22
|
isSuccess: false,
|
|
22
23
|
isError: false,
|
|
@@ -32,6 +33,7 @@ export class ResourceAgent {
|
|
|
32
33
|
return {
|
|
33
34
|
isInitiated: currState.isInitiated || !!prevState,
|
|
34
35
|
isLoading: currState.isLoading,
|
|
36
|
+
isInitialLoading: currState.isLoading && !currState.isDone && !prevState?.isDone,
|
|
35
37
|
isDone: currState.isDone,
|
|
36
38
|
isSuccess: currState.isSuccess,
|
|
37
39
|
isError: currState.isError,
|
|
@@ -76,8 +76,10 @@ export type ResourceAgentInstance<D extends ResourceDefinition> = {
|
|
|
76
76
|
export type ResourceQueryState<D extends ResourceDefinition> = {
|
|
77
77
|
/** Инициализирован ли хотя бы один запрос */
|
|
78
78
|
isInitiated: boolean;
|
|
79
|
-
/**
|
|
79
|
+
/** Загрузка */
|
|
80
80
|
isLoading: boolean;
|
|
81
|
+
/** Первая загрузка */
|
|
82
|
+
isInitialLoading: boolean;
|
|
81
83
|
/** Завершен ли запрос */
|
|
82
84
|
isDone: boolean;
|
|
83
85
|
/** Успешно ли завершен последний запрос (false по умолчанию) */
|
|
@@ -2,6 +2,7 @@ import { SubscriptionLike } from "rxjs";
|
|
|
2
2
|
export declare class Effect implements SubscriptionLike {
|
|
3
3
|
private _onComplete?;
|
|
4
4
|
private _subscriptions;
|
|
5
|
+
protected readonly _scopeDestroyedSub: import("rxjs").Subscription | undefined;
|
|
5
6
|
closed: boolean;
|
|
6
7
|
_rang: number;
|
|
7
8
|
constructor(effectFn: (ctx: (fn: () => void) => void) => void, _onComplete?: (() => void) | undefined);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Batcher, Tracker } from "../base";
|
|
2
|
+
import { SharedOptions } from "../../common/options/SharedOptions";
|
|
2
3
|
export class Effect {
|
|
3
4
|
_onComplete;
|
|
4
5
|
_subscriptions = [];
|
|
6
|
+
_scopeDestroyedSub = SharedOptions.getScopeDestroyed$?.()?.subscribe(() => {
|
|
7
|
+
this.complete();
|
|
8
|
+
});
|
|
5
9
|
closed = false;
|
|
6
10
|
_rang = 0;
|
|
7
11
|
constructor(effectFn, _onComplete) {
|
|
@@ -60,6 +64,7 @@ export class Effect {
|
|
|
60
64
|
return;
|
|
61
65
|
this.closed = true;
|
|
62
66
|
this._subscriptions.forEach((sub) => sub.unsubscribe());
|
|
67
|
+
this._scopeDestroyedSub?.unsubscribe();
|
|
63
68
|
this._onComplete?.();
|
|
64
69
|
}
|
|
65
70
|
/**
|
|
@@ -4,6 +4,7 @@ import { StateDevtoolsOptions } from "../../common/devtools";
|
|
|
4
4
|
export declare class Signal<T> extends BehaviorSubject<T> implements SubscriptionLike, SignalLike<T> {
|
|
5
5
|
private readonly _stateDevtools;
|
|
6
6
|
protected _rang: number;
|
|
7
|
+
protected readonly _scopeDestroyedSub: import("rxjs").Subscription | undefined;
|
|
7
8
|
constructor(initialValue: T, options?: StateDevtoolsOptions);
|
|
8
9
|
protected _onChange(value: T): void;
|
|
9
10
|
get value(): T;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { BehaviorSubject } from "rxjs";
|
|
2
2
|
import { Batcher, Tracker, Devtools } from "../base";
|
|
3
|
+
import { SharedOptions } from "../../common/options/SharedOptions";
|
|
3
4
|
export class Signal extends BehaviorSubject {
|
|
4
5
|
_stateDevtools;
|
|
5
6
|
_rang = 0;
|
|
7
|
+
_scopeDestroyedSub = SharedOptions.getScopeDestroyed$?.()?.subscribe(() => {
|
|
8
|
+
this.complete();
|
|
9
|
+
});
|
|
6
10
|
constructor(initialValue, options) {
|
|
7
11
|
super(initialValue);
|
|
8
12
|
this._stateDevtools = Devtools.createState(initialValue, {
|
|
@@ -48,7 +52,8 @@ export class Signal extends BehaviorSubject {
|
|
|
48
52
|
return this.next(value);
|
|
49
53
|
}
|
|
50
54
|
complete() {
|
|
51
|
-
this._stateDevtools?.('$
|
|
55
|
+
this._stateDevtools?.('$COMPLETED');
|
|
56
|
+
this._scopeDestroyedSub?.unsubscribe();
|
|
52
57
|
super.complete();
|
|
53
58
|
}
|
|
54
59
|
/**
|