-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.ts
More file actions
44 lines (40 loc) · 1.16 KB
/
action.ts
File metadata and controls
44 lines (40 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
export type * from "@vim-fall/core/action";
import type { Denops } from "@denops/std";
import type { Action, InvokeParams } from "@vim-fall/core/action";
import { type DerivableArray, deriveArray } from "@vim-fall/custom/derivable";
import type { Detail, DetailUnit } from "./item.ts";
import type { Promish } from "./util/_typeutil.ts";
/**
* Defines an action.
*
* @param invoke - The function to invoke the action.
* @returns The defined action.
*/
export function defineAction<T extends Detail = DetailUnit>(
invoke: (
denops: Denops,
params: InvokeParams<T>,
options: { signal?: AbortSignal },
) => Promish<void | true>,
): Action<T> {
return { invoke };
}
/**
* Composes multiple actions.
*
* The actions are invoked sequentially in the order they are passed.
*
* @param actions - The actions to compose.
* @returns The composed action.
*/
export function composeActions<T extends Detail>(
...actions: DerivableArray<[Action<T>, ...Action<T>[]]>
): Action<T> {
return {
invoke: async (denops, params, options) => {
for (const action of deriveArray(actions)) {
await action.invoke(denops, params, options);
}
},
};
}