@diphyx/harlemify 6.4.0 → 6.4.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.
package/dist/module.json
CHANGED
|
@@ -3,6 +3,13 @@ import { ActionStatus, type ActionCall, type ActionApiCall, type ActionHandlerCa
|
|
|
3
3
|
export interface UseStoreActionOptions {
|
|
4
4
|
isolated?: boolean;
|
|
5
5
|
}
|
|
6
|
+
type ResolveCallOptions<C> = C extends ActionHandlerCall<infer P, any> ? ActionHandlerCallOptions<P> : C extends ActionApiCall<any> ? ActionApiCallOptions : ActionCallOptions;
|
|
7
|
+
export type IsolatedActionCall<C> = C extends ActionHandlerCall<infer P, any> ? {
|
|
8
|
+
payload: Readonly<Ref<P | undefined>>;
|
|
9
|
+
} : C extends ActionApiCall<any> ? {
|
|
10
|
+
params: Readonly<Ref<Record<string, string | number> | undefined>>;
|
|
11
|
+
query: Readonly<Ref<Record<string, unknown> | undefined>>;
|
|
12
|
+
} : object;
|
|
6
13
|
export type UseStoreAction<T, O = ActionCallOptions> = {
|
|
7
14
|
execute: (options?: Omit<O, "bind">) => Promise<T>;
|
|
8
15
|
error: Readonly<Ref<Error | null>>;
|
|
@@ -14,4 +21,10 @@ export declare function useIsolatedActionError(): Ref<Error | null>;
|
|
|
14
21
|
export declare function useIsolatedActionStatus(): Ref<ActionStatus>;
|
|
15
22
|
export declare function useStoreAction<A extends Record<string, ActionCall<any>>, K extends keyof A & string, T = Awaited<ReturnType<A[K]>>>(store: {
|
|
16
23
|
action: A;
|
|
17
|
-
}, key: K, options
|
|
24
|
+
}, key: K, options: UseStoreActionOptions & {
|
|
25
|
+
isolated: true;
|
|
26
|
+
}): UseStoreAction<T, ResolveCallOptions<A[K]>> & IsolatedActionCall<A[K]>;
|
|
27
|
+
export declare function useStoreAction<A extends Record<string, ActionCall<any>>, K extends keyof A & string, T = Awaited<ReturnType<A[K]>>>(store: {
|
|
28
|
+
action: A;
|
|
29
|
+
}, key: K, options?: UseStoreActionOptions): UseStoreAction<T, ResolveCallOptions<A[K]>>;
|
|
30
|
+
export {};
|
|
@@ -2,6 +2,7 @@ import { ref, computed } from "vue";
|
|
|
2
2
|
import {
|
|
3
3
|
ActionStatus
|
|
4
4
|
} from "../core/types/action.js";
|
|
5
|
+
import { snapshot } from "../core/utils/base.js";
|
|
5
6
|
export function useIsolatedActionError() {
|
|
6
7
|
return ref(null);
|
|
7
8
|
}
|
|
@@ -13,6 +14,9 @@ export function useStoreAction(store, key, options) {
|
|
|
13
14
|
if (!action) {
|
|
14
15
|
throw new Error(`Action "${key}" not found in store`);
|
|
15
16
|
}
|
|
17
|
+
const params = ref();
|
|
18
|
+
const query = ref();
|
|
19
|
+
const payload = ref();
|
|
16
20
|
let error;
|
|
17
21
|
let status;
|
|
18
22
|
let loading;
|
|
@@ -28,6 +32,9 @@ export function useStoreAction(store, key, options) {
|
|
|
28
32
|
reset = () => {
|
|
29
33
|
isolatedStatus.value = ActionStatus.IDLE;
|
|
30
34
|
isolatedError.value = null;
|
|
35
|
+
params.value = void 0;
|
|
36
|
+
query.value = void 0;
|
|
37
|
+
payload.value = void 0;
|
|
31
38
|
};
|
|
32
39
|
} else {
|
|
33
40
|
error = action.error;
|
|
@@ -41,6 +48,12 @@ export function useStoreAction(store, key, options) {
|
|
|
41
48
|
status,
|
|
42
49
|
error
|
|
43
50
|
};
|
|
51
|
+
if (!loading.value) {
|
|
52
|
+
const isolatedCall = callOptions;
|
|
53
|
+
params.value = snapshot(isolatedCall.params);
|
|
54
|
+
query.value = snapshot(isolatedCall.query);
|
|
55
|
+
payload.value = snapshot(isolatedCall.payload);
|
|
56
|
+
}
|
|
44
57
|
}
|
|
45
58
|
return action(callOptions);
|
|
46
59
|
}
|
|
@@ -49,6 +62,9 @@ export function useStoreAction(store, key, options) {
|
|
|
49
62
|
error,
|
|
50
63
|
status,
|
|
51
64
|
loading,
|
|
52
|
-
reset
|
|
65
|
+
reset,
|
|
66
|
+
params,
|
|
67
|
+
query,
|
|
68
|
+
payload
|
|
53
69
|
};
|
|
54
70
|
}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type { ComposeCallback, ComposeCall, ComposeDefinitions, ComposeContext,
|
|
|
13
13
|
export { useStoreCompose } from "./composables/compose.js";
|
|
14
14
|
export type { UseStoreCompose } from "./composables/compose.js";
|
|
15
15
|
export { useIsolatedActionStatus, useIsolatedActionError, useStoreAction } from "./composables/action.js";
|
|
16
|
-
export type { UseStoreActionOptions, UseStoreAction } from "./composables/action.js";
|
|
16
|
+
export type { UseStoreActionOptions, UseStoreAction, IsolatedActionCall } from "./composables/action.js";
|
|
17
17
|
export { useStoreModel } from "./composables/model.js";
|
|
18
18
|
export type { UseStoreModelOptions, UseStoreModel } from "./composables/model.js";
|
|
19
19
|
export { useStoreView } from "./composables/view.js";
|