vovk 3.2.0 → 3.2.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.
@@ -28,8 +28,8 @@ export declare function createFetcher<T>({ prepareRequestInit, transformResponse
28
28
  onSuccess?: CreateFetcherOnSuccess<T>;
29
29
  onError?: CreateFetcherOnError<T>;
30
30
  }): VovkFetcher<VovkFetcherOptions<T>> & {
31
- onSuccess(cb: CreateFetcherOnSuccess<T>): void;
32
- onError(cb: CreateFetcherOnError<T>): void;
31
+ onSuccess(cb: CreateFetcherOnSuccess<T>): () => void;
32
+ onError(cb: CreateFetcherOnError<T>): () => void;
33
33
  };
34
34
  /**
35
35
  * Default fetcher implementation for client requests.
@@ -44,6 +44,6 @@ export declare const fetcher: VovkFetcher<{
44
44
  interpretAs?: string;
45
45
  init?: RequestInit;
46
46
  }> & {
47
- onSuccess(cb: CreateFetcherOnSuccess<unknown>): void;
48
- onError(cb: CreateFetcherOnError<unknown>): void;
47
+ onSuccess(cb: CreateFetcherOnSuccess<unknown>): () => void;
48
+ onError(cb: CreateFetcherOnError<unknown>): () => void;
49
49
  };
@@ -129,9 +129,19 @@ export function createFetcher({ prepareRequestInit, transformResponse, onSuccess
129
129
  return Object.assign(newFetcher, {
130
130
  onSuccess(cb) {
131
131
  onSuccessCallbacks.push(cb);
132
+ return () => {
133
+ const index = onSuccessCallbacks.indexOf(cb);
134
+ if (index !== -1)
135
+ onSuccessCallbacks.splice(index, 1);
136
+ };
132
137
  },
133
138
  onError(cb) {
134
139
  onErrorCallbacks.push(cb);
140
+ return () => {
141
+ const index = onErrorCallbacks.indexOf(cb);
142
+ if (index !== -1)
143
+ onErrorCallbacks.splice(index, 1);
144
+ };
135
145
  },
136
146
  });
137
147
  }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  ],
8
8
  "main": "./dist/index.js",
9
9
  "types": "./dist/index.d.ts",
10
- "version": "3.2.0",
10
+ "version": "3.2.2",
11
11
  "bin": {
12
12
  "vovk-cli-npx": "./bin/index.mjs"
13
13
  },