@fozy-labs/rx-toolkit 0.4.8 → 0.4.10

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,7 @@
1
1
  import type { DevtoolsLike } from "../../common/devtools";
2
2
  type Update = Partial<{
3
3
  DEVTOOLS: DevtoolsLike | null;
4
- onError: (error: unknown) => void;
4
+ onQueryError: (error: unknown) => void;
5
5
  }>;
6
6
  export declare class DefaultOptions {
7
7
  static update(part: Update): void;
@@ -3,7 +3,7 @@ export class DefaultOptions {
3
3
  static update(part) {
4
4
  if (part.DEVTOOLS !== undefined)
5
5
  SharedOptions.DEVTOOLS = part.DEVTOOLS;
6
- if (part.onError !== undefined)
7
- SharedOptions.onError = part.onError;
6
+ if (part.onQueryError !== undefined)
7
+ SharedOptions.onQueryError = part.onQueryError;
8
8
  }
9
9
  }
@@ -1,5 +1,5 @@
1
1
  import { DevtoolsLike } from "../../common/devtools";
2
2
  export declare class SharedOptions {
3
3
  static DEVTOOLS: DevtoolsLike | null;
4
- static onError: ((error: unknown) => void) | null;
4
+ static onQueryError: ((error: unknown) => void) | null;
5
5
  }
@@ -1,4 +1,4 @@
1
1
  export class SharedOptions {
2
2
  static DEVTOOLS = null;
3
- static onError = null;
3
+ static onQueryError = null;
4
4
  }
@@ -59,7 +59,7 @@ export class Operation {
59
59
  constructor(_options) {
60
60
  this._options = _options;
61
61
  this._queriesCache = new QueriesCache(this._options.cacheLifetime ?? this._DEFAULT_CACHE_LIFETIME);
62
- this._hooks = new QueriesLifetimeHooks(_options, 'Operation');
62
+ this._hooks = new QueriesLifetimeHooks(_options, _options.devtoolsName ?? 'Operation');
63
63
  this._createLinks();
64
64
  }
65
65
  _createLinks() {
@@ -31,14 +31,11 @@ export class QueriesLifetimeHooks {
31
31
  });
32
32
  }
33
33
  }
34
- if (SharedOptions.onError) {
35
- this.onQueryStartedListeners.push(async (args, { $queryFulfilled }) => {
36
- try {
37
- await $queryFulfilled;
38
- }
39
- catch (error) {
40
- SharedOptions.onError(error);
41
- }
34
+ if (SharedOptions.onQueryError) {
35
+ this.onQueryStartedListeners.push(async (_, { $queryFulfilled }) => {
36
+ const result = await $queryFulfilled;
37
+ if (result.isError)
38
+ SharedOptions.onQueryError(result.error);
42
39
  });
43
40
  }
44
41
  }
@@ -108,7 +108,7 @@ export class Resource {
108
108
  _DEFAULT_CACHE_LIFETIME = 60_000;
109
109
  constructor(_options) {
110
110
  this._options = _options;
111
- this._hooks = new QueriesLifetimeHooks(_options, 'Resource');
111
+ this._hooks = new QueriesLifetimeHooks(_options, _options.devtoolsName ?? 'Resource');
112
112
  this._queriesCache = new QueriesCache(_options.cacheLifetime ?? this._DEFAULT_CACHE_LIFETIME);
113
113
  }
114
114
  createAgent = () => {
@@ -33,6 +33,10 @@ export type OperationCreateOptions<D extends OperationDefinition> = {
33
33
  * - завершение запроса с результатом или ошибкой
34
34
  */
35
35
  onQueryStarted?: OnQueryStarted<D["Args"], D["Result"]>;
36
+ /**
37
+ * Имя для инструментов разработчика (DevTools)
38
+ */
39
+ devtoolsName?: string | undefined | null;
36
40
  };
37
41
  /**
38
42
  * Настройки связи операции с ресурсом
@@ -31,6 +31,10 @@ export type ResourceCreateOptions<D extends ResourceDefinition> = {
31
31
  * - завершение запроса с результатом или ошибкой
32
32
  */
33
33
  onQueryStarted?: OnQueryStarted<D["Args"], D["Result"]>;
34
+ /**
35
+ * Имя ресурса в инструментах разработчика
36
+ */
37
+ devtoolsName?: string | undefined | null;
34
38
  };
35
39
  /**
36
40
  * Определение типов ресурса
@@ -8,6 +8,9 @@ export declare class Computed<T> extends Signal<T> implements SubscriptionLike,
8
8
  disableDevtools?: boolean;
9
9
  devtoolsName?: string;
10
10
  });
11
- unsubscribe(): void;
12
11
  complete(): void;
12
+ /**
13
+ * @deprecated use 'complete()' instead
14
+ */
15
+ unsubscribe(): void;
13
16
  }
@@ -21,13 +21,16 @@ export class Computed extends Signal {
21
21
  });
22
22
  this._effect = effect;
23
23
  }
24
- unsubscribe() {
25
- this.complete();
26
- }
27
24
  complete() {
28
25
  if (this.closed)
29
26
  return;
30
- this._effect.unsubscribe();
27
+ this._effect.complete();
31
28
  super.complete();
32
29
  }
30
+ /**
31
+ * @deprecated use 'complete()' instead
32
+ */
33
+ unsubscribe() {
34
+ this.complete();
35
+ }
33
36
  }
@@ -9,6 +9,9 @@ export declare class Effect implements SubscriptionLike {
9
9
  * Выполняет функцию в tracked-контексте, подписываясь на Tracker.
10
10
  */
11
11
  private _runInTrackedContext;
12
- unsubscribe(): void;
13
12
  complete(): void;
13
+ /**
14
+ * @deprecated Use `complete()` method instead.
15
+ */
16
+ unsubscribe(): void;
14
17
  }
@@ -41,11 +41,11 @@ export class Effect {
41
41
  }));
42
42
  },
43
43
  complete: () => {
44
- this.unsubscribe();
44
+ this.complete();
45
45
  },
46
46
  error: (err) => {
47
47
  console.error(err);
48
- this.unsubscribe();
48
+ this.complete();
49
49
  },
50
50
  });
51
51
  effectFn((fn) => {
@@ -56,9 +56,6 @@ export class Effect {
56
56
  scheduler = Batcher.scheduler(this._rang);
57
57
  prevSubscriptions?.forEach((sub) => sub.unsubscribe());
58
58
  }
59
- unsubscribe() {
60
- this.complete();
61
- }
62
59
  complete() {
63
60
  if (this.closed)
64
61
  return;
@@ -66,4 +63,10 @@ export class Effect {
66
63
  this._subscriptions.forEach((sub) => sub.unsubscribe());
67
64
  this._onComplete?.();
68
65
  }
66
+ /**
67
+ * @deprecated Use `complete()` method instead.
68
+ */
69
+ unsubscribe() {
70
+ this.complete();
71
+ }
69
72
  }
@@ -1,10 +1,10 @@
1
- import { BehaviorSubject, Observable } from "rxjs";
1
+ import { BehaviorSubject, Observable, SubscriptionLike } from "rxjs";
2
2
  import type { ReadableSignalLike, SignalLike, UnaryFunction } from "./types";
3
3
  type SignalOptions = {
4
4
  disableDevtools?: boolean;
5
5
  devtoolsName?: string;
6
6
  };
7
- export declare class Signal<T> extends BehaviorSubject<T> implements SignalLike<T> {
7
+ export declare class Signal<T> extends BehaviorSubject<T> implements SubscriptionLike, SignalLike<T> {
8
8
  private readonly _devtools;
9
9
  protected _rang: number;
10
10
  constructor(initialValue: T, options?: SignalOptions);
@@ -26,6 +26,11 @@ export declare class Signal<T> extends BehaviorSubject<T> implements SignalLike<
26
26
  */
27
27
  set(value: T): void;
28
28
  complete(): void;
29
+ /**
30
+ * @deprecated use `complete()` instead.
31
+ */
32
+ unsubscribe(): void;
33
+ asReadonly(): ReadableSignalLike<T>;
29
34
  pipe(): Signal<T>;
30
35
  pipe<A extends Observable<any>>(op1: UnaryFunction<ReadableSignalLike<T>, A>): A;
31
36
  pipe<A extends Observable<any>, B extends Observable<any>>(op1: UnaryFunction<Signal<T>, A>, op2: UnaryFunction<A, B>): B;
@@ -37,6 +42,5 @@ export declare class Signal<T> extends BehaviorSubject<T> implements SignalLike<
37
42
  pipe<A extends Observable<any>, B extends Observable<any>, C extends Observable<any>, D extends Observable<any>, E extends Observable<any>, F extends Observable<any>, G extends Observable<any>, H extends Observable<any>>(op1: UnaryFunction<Signal<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>): H;
38
43
  pipe<A extends Observable<any>, B extends Observable<any>, C extends Observable<any>, D extends Observable<any>, E extends Observable<any>, F extends Observable<any>, G extends Observable<any>, H extends Observable<any>, I extends Observable<any>>(op1: UnaryFunction<Signal<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>, op9: UnaryFunction<H, I>): I;
39
44
  pipe<A extends Observable<any>, B extends Observable<any>, C extends Observable<any>, D extends Observable<any>, E extends Observable<any>, F extends Observable<any>, G extends Observable<any>, H extends Observable<any>, I extends Observable<any>>(op1: UnaryFunction<Signal<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>, op9: UnaryFunction<H, I>, ...operations: UnaryFunction<Observable<any>, Observable<any>>[]): Observable<unknown>;
40
- asReadonly(): ReadableSignalLike<T>;
41
45
  }
42
46
  export {};
@@ -56,12 +56,18 @@ export class Signal extends BehaviorSubject {
56
56
  this._devtools?.('$COMPLETE');
57
57
  super.complete();
58
58
  }
59
- pipe(...operations) {
60
- return operations.reduce(pipeReducer, this);
59
+ /**
60
+ * @deprecated use `complete()` instead.
61
+ */
62
+ unsubscribe() {
63
+ this.complete();
61
64
  }
62
65
  asReadonly() {
63
66
  return this;
64
67
  }
68
+ pipe(...operations) {
69
+ return operations.reduce(pipeReducer, this);
70
+ }
65
71
  }
66
72
  function pipeReducer(prev, fn) {
67
73
  return fn(prev);
@@ -0,0 +1,7 @@
1
+ ```shell
2
+ npm run ts-check
3
+ npm run build
4
+ npm version patch
5
+ npm publish
6
+ git push origin develop --tag
7
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fozy-labs/rx-toolkit",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",