@fozy-labs/rx-toolkit 0.4.12 → 0.4.14

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.
@@ -1,7 +1,10 @@
1
1
  import type { DevtoolsLike } from "../../common/devtools";
2
+ import { Observable } from "rxjs";
2
3
  type Update = Partial<{
3
4
  DEVTOOLS: DevtoolsLike | null;
4
5
  onQueryError: (error: unknown) => void;
6
+ getScopeName: () => string | null;
7
+ getScopeDestroyed$: () => Observable<void> | null;
5
8
  }>;
6
9
  export declare class DefaultOptions {
7
10
  static update(part: Update): void;
@@ -5,5 +5,9 @@ export class DefaultOptions {
5
5
  SharedOptions.DEVTOOLS = part.DEVTOOLS;
6
6
  if (part.onQueryError !== undefined)
7
7
  SharedOptions.onQueryError = part.onQueryError;
8
+ if (part.getScopeName !== undefined)
9
+ SharedOptions.getScopeName = part.getScopeName;
10
+ if (part.getScopeDestroyed$ !== undefined)
11
+ SharedOptions.getScopeDestroyed$ = part.getScopeDestroyed$;
8
12
  }
9
13
  }
@@ -1,5 +1,8 @@
1
1
  import { DevtoolsLike } from "../../common/devtools";
2
+ import { Observable } from "rxjs";
2
3
  export declare class SharedOptions {
3
4
  static DEVTOOLS: DevtoolsLike | null;
4
5
  static onQueryError: ((error: unknown) => void) | null;
6
+ static getScopeName: () => string | null;
7
+ static getScopeDestroyed$: () => Observable<void> | null;
5
8
  }
@@ -1,4 +1,6 @@
1
1
  export class SharedOptions {
2
2
  static DEVTOOLS = null;
3
3
  static onQueryError = null;
4
+ static getScopeName;
5
+ static getScopeDestroyed$;
4
6
  }
@@ -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 по умолчанию) */
@@ -20,6 +20,10 @@ export const Devtools = {
20
20
  function createKey(name, base) {
21
21
  const i = Indexer.getIndex();
22
22
  let key = '';
23
+ if (name?.includes('{scope}')) {
24
+ const scopeName = SharedOptions.getScopeName?.() || '#global';
25
+ name = name.replace('{scope}', scopeName);
26
+ }
23
27
  if (base && name)
24
28
  key += name.replace('{base}', base);
25
29
  else if (!base && name)
@@ -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, {
@@ -49,6 +53,7 @@ export class Signal extends BehaviorSubject {
49
53
  }
50
54
  complete() {
51
55
  this._stateDevtools?.('$COMPLETE');
56
+ this._scopeDestroyedSub?.unsubscribe();
52
57
  super.complete();
53
58
  }
54
59
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fozy-labs/rx-toolkit",
3
- "version": "0.4.12",
3
+ "version": "0.4.14",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",