@webamoki/web-svelte 2.5.3 → 2.6.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.
|
@@ -7,7 +7,7 @@ type RC<S, O extends CommandSuccess> = RemoteCommand<S, Promise<CommandResult<O>
|
|
|
7
7
|
* - execute function, which handles toast and callbacks
|
|
8
8
|
* - submitting state for tracking pending executions
|
|
9
9
|
*/
|
|
10
|
-
export declare class
|
|
10
|
+
export declare class CommandActionState<S, O extends CommandSuccess> {
|
|
11
11
|
#private;
|
|
12
12
|
input: S;
|
|
13
13
|
get submitting(): boolean;
|
|
@@ -20,8 +20,29 @@ export declare class CommandAction<S, O extends CommandSuccess> {
|
|
|
20
20
|
toastError?: boolean;
|
|
21
21
|
toastSuccess?: boolean;
|
|
22
22
|
});
|
|
23
|
+
/** Executes the command with the current input. */
|
|
23
24
|
execute(): Promise<void>;
|
|
24
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Command Remote function handler for Client
|
|
28
|
+
* - execute function takes input and handles toast and callbacks
|
|
29
|
+
* - submitting state for tracking pending executions
|
|
30
|
+
*/
|
|
31
|
+
export declare class CommandAction<S, O extends CommandSuccess> {
|
|
32
|
+
#private;
|
|
33
|
+
get submitting(): boolean;
|
|
34
|
+
constructor(remote: RC<S, O>, config?: {
|
|
35
|
+
onError?: (error: ResponseError) => void;
|
|
36
|
+
onSuccess?: (state: {
|
|
37
|
+
input: S;
|
|
38
|
+
result: O;
|
|
39
|
+
}) => void;
|
|
40
|
+
toastError?: boolean;
|
|
41
|
+
toastSuccess?: boolean;
|
|
42
|
+
});
|
|
43
|
+
/** Executes the command with the provided input. */
|
|
44
|
+
execute(input: S): Promise<void>;
|
|
45
|
+
}
|
|
25
46
|
type RCV<O extends CommandSuccess> = RemoteCommand<void, Promise<CommandResult<O>>>;
|
|
26
47
|
/**
|
|
27
48
|
* Command Remote function handler for Client without input
|
|
@@ -7,7 +7,7 @@ import { Result } from './functional/result.js';
|
|
|
7
7
|
* - execute function, which handles toast and callbacks
|
|
8
8
|
* - submitting state for tracking pending executions
|
|
9
9
|
*/
|
|
10
|
-
export class
|
|
10
|
+
export class CommandActionState {
|
|
11
11
|
input = $state();
|
|
12
12
|
get submitting() {
|
|
13
13
|
return this.#submitCount > 0;
|
|
@@ -26,10 +26,58 @@ export class CommandAction {
|
|
|
26
26
|
this.#onError = config?.onError;
|
|
27
27
|
this.#onSuccess = config?.onSuccess;
|
|
28
28
|
}
|
|
29
|
+
/** Executes the command with the current input. */
|
|
29
30
|
async execute() {
|
|
31
|
+
const input = this.input;
|
|
32
|
+
this.#submitCount++;
|
|
33
|
+
try {
|
|
34
|
+
const result = await this.#remote(input).catch(() => Result.err({ code: 500, message: 'Internal Server Error' }));
|
|
35
|
+
if (result.ok) {
|
|
36
|
+
if (this.#toastSuccess)
|
|
37
|
+
toast.success(result.value.message);
|
|
38
|
+
this.#onSuccess?.({
|
|
39
|
+
input: input,
|
|
40
|
+
result: result.value
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (this.#toastError)
|
|
46
|
+
toast.error(`${result.error.code} - ${result.error.message}`);
|
|
47
|
+
this.#onError?.(result.error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
this.#submitCount--;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Command Remote function handler for Client
|
|
57
|
+
* - execute function takes input and handles toast and callbacks
|
|
58
|
+
* - submitting state for tracking pending executions
|
|
59
|
+
*/
|
|
60
|
+
export class CommandAction {
|
|
61
|
+
get submitting() {
|
|
62
|
+
return this.#submitCount > 0;
|
|
63
|
+
}
|
|
64
|
+
#onError;
|
|
65
|
+
#onSuccess;
|
|
66
|
+
#remote;
|
|
67
|
+
#submitCount = $state(0);
|
|
68
|
+
#toastError;
|
|
69
|
+
#toastSuccess;
|
|
70
|
+
constructor(remote, config) {
|
|
71
|
+
this.#remote = remote;
|
|
72
|
+
this.#toastError = config?.toastError ?? true;
|
|
73
|
+
this.#toastSuccess = config?.toastSuccess ?? true;
|
|
74
|
+
this.#onError = config?.onError;
|
|
75
|
+
this.#onSuccess = config?.onSuccess;
|
|
76
|
+
}
|
|
77
|
+
/** Executes the command with the provided input. */
|
|
78
|
+
async execute(input) {
|
|
30
79
|
this.#submitCount++;
|
|
31
80
|
try {
|
|
32
|
-
const input = this.input;
|
|
33
81
|
const result = await this.#remote(input).catch(() => Result.err({ code: 500, message: 'Internal Server Error' }));
|
|
34
82
|
if (result.ok) {
|
|
35
83
|
if (this.#toastSuccess)
|