floppy-disk 1.1.1 → 1.1.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.
@@ -10,7 +10,14 @@ export declare type MutationState<TVar, TResponse = any, TError = unknown> = {
10
10
  responseUpdatedAt: number | null;
11
11
  error: TError | null;
12
12
  errorUpdatedAt: number | null;
13
- mutate: (variables?: TVar) => Promise<TResponse>;
13
+ /**
14
+ * Mutate function is a promise that will always resolve.
15
+ */
16
+ mutate: (variables?: TVar) => Promise<{
17
+ response?: TResponse;
18
+ error?: TError;
19
+ variables?: TVar;
20
+ }>;
14
21
  };
15
22
  export declare type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = InitStoreOptions<MutationState<TVar, TResponse, TError>> & {
16
23
  onMutate?: (variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
@@ -14,7 +14,7 @@ export const createMutation = (mutationFn, options = {}) => {
14
14
  set({ isWaiting: true });
15
15
  const stateBeforeMutate = get();
16
16
  onMutate(variables, stateBeforeMutate);
17
- return new Promise((resolve, reject) => {
17
+ return new Promise((resolve) => {
18
18
  mutationFn(variables, stateBeforeMutate)
19
19
  .then((response) => {
20
20
  set({
@@ -27,7 +27,7 @@ export const createMutation = (mutationFn, options = {}) => {
27
27
  errorUpdatedAt: null,
28
28
  });
29
29
  onSuccess(response, variables, stateBeforeMutate);
30
- resolve(response);
30
+ resolve({ response, variables });
31
31
  })
32
32
  .catch((error) => {
33
33
  set({
@@ -38,7 +38,7 @@ export const createMutation = (mutationFn, options = {}) => {
38
38
  errorUpdatedAt: Date.now(),
39
39
  });
40
40
  onError(error, variables, stateBeforeMutate);
41
- reject(error);
41
+ resolve({ error, variables });
42
42
  })
43
43
  .finally(() => {
44
44
  onSettled(variables, stateBeforeMutate);
@@ -10,7 +10,14 @@ export declare type MutationState<TVar, TResponse = any, TError = unknown> = {
10
10
  responseUpdatedAt: number | null;
11
11
  error: TError | null;
12
12
  errorUpdatedAt: number | null;
13
- mutate: (variables?: TVar) => Promise<TResponse>;
13
+ /**
14
+ * Mutate function is a promise that will always resolve.
15
+ */
16
+ mutate: (variables?: TVar) => Promise<{
17
+ response?: TResponse;
18
+ error?: TError;
19
+ variables?: TVar;
20
+ }>;
14
21
  };
15
22
  export declare type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = InitStoreOptions<MutationState<TVar, TResponse, TError>> & {
16
23
  onMutate?: (variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
@@ -17,7 +17,7 @@ const createMutation = (mutationFn, options = {}) => {
17
17
  set({ isWaiting: true });
18
18
  const stateBeforeMutate = get();
19
19
  onMutate(variables, stateBeforeMutate);
20
- return new Promise((resolve, reject) => {
20
+ return new Promise((resolve) => {
21
21
  mutationFn(variables, stateBeforeMutate)
22
22
  .then((response) => {
23
23
  set({
@@ -30,7 +30,7 @@ const createMutation = (mutationFn, options = {}) => {
30
30
  errorUpdatedAt: null,
31
31
  });
32
32
  onSuccess(response, variables, stateBeforeMutate);
33
- resolve(response);
33
+ resolve({ response, variables });
34
34
  })
35
35
  .catch((error) => {
36
36
  set({
@@ -41,7 +41,7 @@ const createMutation = (mutationFn, options = {}) => {
41
41
  errorUpdatedAt: Date.now(),
42
42
  });
43
43
  onError(error, variables, stateBeforeMutate);
44
- reject(error);
44
+ resolve({ error, variables });
45
45
  })
46
46
  .finally(() => {
47
47
  onSettled(variables, stateBeforeMutate);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floppy-disk",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "FloppyDisk - lightweight, simple, and powerful state management library",
5
5
  "keywords": [
6
6
  "state",