@astral/mobx-query 1.6.1 → 1.6.2

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.
@@ -30,7 +30,7 @@ export declare class AuxiliaryQuery<TResult, TError = void> {
30
30
  * Метод ответственный за создание единого промиса,
31
31
  * для устранения гонки запросов
32
32
  */
33
- getUnifiedPromise: (executor: Executor<TResult>) => Promise<TResult>;
33
+ getUnifiedPromise: (executor: Executor<TResult>, onSuccess?: ((data: TResult) => void) | undefined) => Promise<TResult>;
34
34
  private setSuccess;
35
35
  private checkBackgroundAndSet;
36
36
  /**
@@ -22,13 +22,14 @@ export class AuxiliaryQuery {
22
22
  * Метод ответственный за создание единого промиса,
23
23
  * для устранения гонки запросов
24
24
  */
25
- this.getUnifiedPromise = (executor) => {
25
+ this.getUnifiedPromise = (executor, onSuccess) => {
26
26
  // проверяем, если синглтона нет, то надо создать
27
27
  if (!Boolean(this.unifiedPromise)) {
28
28
  this.startLoading();
29
29
  this.unifiedPromise = executor()
30
30
  .then((resData) => {
31
31
  runInAction(this.submitSuccess);
32
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(resData);
32
33
  return resData;
33
34
  })
34
35
  .catch((e) => {
@@ -67,10 +67,10 @@ export class InfiniteQuery extends QueryContainer {
67
67
  this.offset += this.incrementCount;
68
68
  // запускаем запрос с последними параметрами, и флагом необходимости инкремента
69
69
  this.auxiliary
70
- .getUnifiedPromise(this.infiniteExecutor)
71
- .then((resData) => {
70
+ .getUnifiedPromise(this.infiniteExecutor, (resData) => {
72
71
  this.submitSuccess(resData, undefined, true);
73
- });
72
+ })
73
+ .catch((e) => { var _a; return (_a = this.defaultOnError) === null || _a === void 0 ? void 0 : _a.call(this, e); });
74
74
  }
75
75
  };
76
76
  /**
@@ -89,8 +89,7 @@ export class InfiniteQuery extends QueryContainer {
89
89
  this.offset = 0;
90
90
  this.isEndReached = false;
91
91
  this.auxiliary
92
- .getUnifiedPromise(this.infiniteExecutor)
93
- .then((resData) => {
92
+ .getUnifiedPromise(this.infiniteExecutor, (resData) => {
94
93
  this.submitSuccess(resData, onSuccess);
95
94
  })
96
95
  .catch((e) => {
@@ -115,16 +114,7 @@ export class InfiniteQuery extends QueryContainer {
115
114
  }
116
115
  this.offset = 0;
117
116
  this.isEndReached = false;
118
- return this.auxiliary
119
- .getUnifiedPromise(this.infiniteExecutor)
120
- .then((resData) => {
121
- this.submitSuccess(resData);
122
- return resData;
123
- })
124
- .catch((e) => {
125
- this.auxiliary.submitError(e);
126
- throw e;
127
- });
117
+ return this.auxiliary.getUnifiedPromise(this.infiniteExecutor, this.submitSuccess);
128
118
  };
129
119
  this.storage = dataStorage;
130
120
  this.incrementCount = incrementCount;
@@ -17,8 +17,7 @@ export class Mutation extends QueryContainer {
17
17
  this.sync = (options) => {
18
18
  const { onSuccess, onError, params } = options || {};
19
19
  this.auxiliary
20
- .getUnifiedPromise(() => this.executor(params))
21
- .then((resData) => {
20
+ .getUnifiedPromise(() => this.executor(params), (resData) => {
22
21
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(resData);
23
22
  })
24
23
  .catch((e) => {
package/Query/Query.js CHANGED
@@ -47,8 +47,7 @@ export class Query extends QueryContainer {
47
47
  this.proceedSync = (options) => {
48
48
  const { onSuccess, onError } = options || {};
49
49
  this.auxiliary
50
- .getUnifiedPromise(this.executor)
51
- .then((res) => {
50
+ .getUnifiedPromise(this.executor, (res) => {
52
51
  this.submitSuccess(res);
53
52
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(res);
54
53
  })
@@ -70,9 +69,7 @@ export class Query extends QueryContainer {
70
69
  if (!this.isNetworkOnly && this.isSuccess && !this.auxiliary.isInvalid) {
71
70
  return Promise.resolve(this.storage.data);
72
71
  }
73
- return this.auxiliary
74
- .getUnifiedPromise(this.executor)
75
- .then(this.submitSuccess);
72
+ return this.auxiliary.getUnifiedPromise(this.executor, this.submitSuccess);
76
73
  };
77
74
  this.defaultOnError = onError;
78
75
  this.enabledAutoFetch = enabledAutoFetch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astral/mobx-query",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "browser": "./index.js",
5
5
  "main": "./index.js",
6
6
  "dependencies": {