floppy-disk 2.0.0 → 2.0.1-beta.1

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.
@@ -13,16 +13,20 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
13
13
  /**
14
14
  * Mutate function is a promise that will always resolve.
15
15
  */
16
- mutate: (variables?: TVar) => Promise<{
16
+ mutate: TVar extends undefined ? () => Promise<{
17
+ response?: TResponse;
18
+ error?: TError;
19
+ variables?: TVar;
20
+ }> : (variables: TVar) => Promise<{
17
21
  response?: TResponse;
18
22
  error?: TError;
19
23
  variables?: TVar;
20
24
  }>;
21
25
  };
22
26
  export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = InitStoreOptions<MutationState<TVar, TResponse, TError>> & {
23
- onMutate?: (variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
24
- onSuccess?: (response: TResponse, variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
25
- onError?: (error: TError, variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
26
- onSettled?: (variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
27
+ onMutate?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
28
+ onSuccess?: (response: TResponse, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
29
+ onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
30
+ onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
27
31
  };
28
- export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar | undefined, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => import("./create-store").UseStore<MutationState<TVar, TResponse, TError>>;
32
+ export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => import("./create-store").UseStore<MutationState<TVar, TResponse, TError>>;
@@ -10,7 +10,7 @@ export const createMutation = (mutationFn, options = {}) => {
10
10
  responseUpdatedAt: null,
11
11
  error: null,
12
12
  errorUpdatedAt: null,
13
- mutate: (variables) => {
13
+ mutate: ((variables) => {
14
14
  set({ isWaiting: true });
15
15
  const stateBeforeMutate = get();
16
16
  onMutate(variables, stateBeforeMutate);
@@ -44,7 +44,7 @@ export const createMutation = (mutationFn, options = {}) => {
44
44
  onSettled(variables, stateBeforeMutate);
45
45
  });
46
46
  });
47
- },
47
+ }),
48
48
  }), createStoreOptions);
49
49
  return useMutation;
50
50
  };
@@ -134,6 +134,7 @@ export const createQuery = (queryFn, options = {}) => {
134
134
  }
135
135
  : {
136
136
  isWaiting: false,
137
+ status: 'error',
137
138
  isError: true,
138
139
  error,
139
140
  errorUpdatedAt,
@@ -13,16 +13,20 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
13
13
  /**
14
14
  * Mutate function is a promise that will always resolve.
15
15
  */
16
- mutate: (variables?: TVar) => Promise<{
16
+ mutate: TVar extends undefined ? () => Promise<{
17
+ response?: TResponse;
18
+ error?: TError;
19
+ variables?: TVar;
20
+ }> : (variables: TVar) => Promise<{
17
21
  response?: TResponse;
18
22
  error?: TError;
19
23
  variables?: TVar;
20
24
  }>;
21
25
  };
22
26
  export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = InitStoreOptions<MutationState<TVar, TResponse, TError>> & {
23
- onMutate?: (variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
24
- onSuccess?: (response: TResponse, variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
25
- onError?: (error: TError, variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
26
- onSettled?: (variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
27
+ onMutate?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
28
+ onSuccess?: (response: TResponse, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
29
+ onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
30
+ onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
27
31
  };
28
- export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar | undefined, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => import("./create-store").UseStore<MutationState<TVar, TResponse, TError>>;
32
+ export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => import("./create-store").UseStore<MutationState<TVar, TResponse, TError>>;
@@ -10,7 +10,7 @@ export const createMutation = (mutationFn, options = {}) => {
10
10
  responseUpdatedAt: null,
11
11
  error: null,
12
12
  errorUpdatedAt: null,
13
- mutate: (variables) => {
13
+ mutate: ((variables) => {
14
14
  set({ isWaiting: true });
15
15
  const stateBeforeMutate = get();
16
16
  onMutate(variables, stateBeforeMutate);
@@ -44,7 +44,7 @@ export const createMutation = (mutationFn, options = {}) => {
44
44
  onSettled(variables, stateBeforeMutate);
45
45
  });
46
46
  });
47
- },
47
+ }),
48
48
  }), createStoreOptions);
49
49
  return useMutation;
50
50
  };
@@ -134,6 +134,7 @@ export const createQuery = (queryFn, options = {}) => {
134
134
  }
135
135
  : {
136
136
  isWaiting: false,
137
+ status: 'error',
137
138
  isError: true,
138
139
  error,
139
140
  errorUpdatedAt,
@@ -13,16 +13,20 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
13
13
  /**
14
14
  * Mutate function is a promise that will always resolve.
15
15
  */
16
- mutate: (variables?: TVar) => Promise<{
16
+ mutate: TVar extends undefined ? () => Promise<{
17
+ response?: TResponse;
18
+ error?: TError;
19
+ variables?: TVar;
20
+ }> : (variables: TVar) => Promise<{
17
21
  response?: TResponse;
18
22
  error?: TError;
19
23
  variables?: TVar;
20
24
  }>;
21
25
  };
22
26
  export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = InitStoreOptions<MutationState<TVar, TResponse, TError>> & {
23
- onMutate?: (variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
24
- onSuccess?: (response: TResponse, variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
25
- onError?: (error: TError, variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
26
- onSettled?: (variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
27
+ onMutate?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
28
+ onSuccess?: (response: TResponse, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
29
+ onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
30
+ onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
27
31
  };
28
- export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar | undefined, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => import("./create-store").UseStore<MutationState<TVar, TResponse, TError>>;
32
+ export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => import("./create-store").UseStore<MutationState<TVar, TResponse, TError>>;
@@ -13,7 +13,7 @@ const createMutation = (mutationFn, options = {}) => {
13
13
  responseUpdatedAt: null,
14
14
  error: null,
15
15
  errorUpdatedAt: null,
16
- mutate: (variables) => {
16
+ mutate: ((variables) => {
17
17
  set({ isWaiting: true });
18
18
  const stateBeforeMutate = get();
19
19
  onMutate(variables, stateBeforeMutate);
@@ -47,7 +47,7 @@ const createMutation = (mutationFn, options = {}) => {
47
47
  onSettled(variables, stateBeforeMutate);
48
48
  });
49
49
  });
50
- },
50
+ }),
51
51
  }), createStoreOptions);
52
52
  return useMutation;
53
53
  };
@@ -137,6 +137,7 @@ const createQuery = (queryFn, options = {}) => {
137
137
  }
138
138
  : {
139
139
  isWaiting: false,
140
+ status: 'error',
140
141
  isError: true,
141
142
  error,
142
143
  errorUpdatedAt,
@@ -13,16 +13,20 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
13
13
  /**
14
14
  * Mutate function is a promise that will always resolve.
15
15
  */
16
- mutate: (variables?: TVar) => Promise<{
16
+ mutate: TVar extends undefined ? () => Promise<{
17
+ response?: TResponse;
18
+ error?: TError;
19
+ variables?: TVar;
20
+ }> : (variables: TVar) => Promise<{
17
21
  response?: TResponse;
18
22
  error?: TError;
19
23
  variables?: TVar;
20
24
  }>;
21
25
  };
22
26
  export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = InitStoreOptions<MutationState<TVar, TResponse, TError>> & {
23
- onMutate?: (variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
24
- onSuccess?: (response: TResponse, variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
25
- onError?: (error: TError, variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
26
- onSettled?: (variables: TVar | undefined, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
27
+ onMutate?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
28
+ onSuccess?: (response: TResponse, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
29
+ onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
30
+ onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
27
31
  };
28
- export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar | undefined, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => import("./create-store").UseStore<MutationState<TVar, TResponse, TError>>;
32
+ export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => import("./create-store").UseStore<MutationState<TVar, TResponse, TError>>;
@@ -13,7 +13,7 @@ const createMutation = (mutationFn, options = {}) => {
13
13
  responseUpdatedAt: null,
14
14
  error: null,
15
15
  errorUpdatedAt: null,
16
- mutate: (variables) => {
16
+ mutate: ((variables) => {
17
17
  set({ isWaiting: true });
18
18
  const stateBeforeMutate = get();
19
19
  onMutate(variables, stateBeforeMutate);
@@ -47,7 +47,7 @@ const createMutation = (mutationFn, options = {}) => {
47
47
  onSettled(variables, stateBeforeMutate);
48
48
  });
49
49
  });
50
- },
50
+ }),
51
51
  }), createStoreOptions);
52
52
  return useMutation;
53
53
  };
@@ -137,6 +137,7 @@ const createQuery = (queryFn, options = {}) => {
137
137
  }
138
138
  : {
139
139
  isWaiting: false,
140
+ status: 'error',
140
141
  isError: true,
141
142
  error,
142
143
  errorUpdatedAt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floppy-disk",
3
- "version": "2.0.0",
3
+ "version": "2.0.1-beta.1",
4
4
  "description": "FloppyDisk - lightweight, simple, and powerful state management library",
5
5
  "keywords": [
6
6
  "state",