|
1 |
| -import { Context, Denops, Dispatcher, Meta } from "../deps.ts"; |
2 |
| - |
3 |
| -class BatchHelper implements Denops { |
4 |
| - #denops: Denops; |
5 |
| - #calls: [string, ...unknown[]][]; |
6 |
| - |
7 |
| - constructor(denops: Denops) { |
8 |
| - this.#denops = denops; |
9 |
| - this.#calls = []; |
10 |
| - } |
11 |
| - |
12 |
| - static getCalls(helper: BatchHelper): [string, ...unknown[]][] { |
13 |
| - return helper.#calls; |
14 |
| - } |
15 |
| - |
16 |
| - get name(): string { |
17 |
| - return this.#denops.name; |
18 |
| - } |
19 |
| - |
20 |
| - get meta(): Meta { |
21 |
| - return this.#denops.meta; |
22 |
| - } |
23 |
| - |
24 |
| - get dispatcher(): Dispatcher { |
25 |
| - return this.#denops.dispatcher; |
26 |
| - } |
27 |
| - |
28 |
| - set dispatcher(dispatcher: Dispatcher) { |
29 |
| - this.#denops.dispatcher = dispatcher; |
30 |
| - } |
31 |
| - |
32 |
| - call(fn: string, ...args: unknown[]): Promise<unknown> { |
33 |
| - this.#calls.push([fn, ...args]); |
34 |
| - return Promise.resolve(); |
35 |
| - } |
36 |
| - |
37 |
| - batch(..._calls: [string, ...unknown[]][]): Promise<unknown[]> { |
38 |
| - throw new Error( |
39 |
| - "The 'batch' method is not available on BatchDenops instance.", |
40 |
| - ); |
41 |
| - } |
42 |
| - |
43 |
| - cmd(cmd: string, ctx: Context = {}): Promise<void> { |
44 |
| - this.call("denops#api#cmd", cmd, ctx); |
45 |
| - return Promise.resolve(); |
46 |
| - } |
47 |
| - |
48 |
| - eval(expr: string, ctx: Context = {}): Promise<unknown> { |
49 |
| - this.call("denops#api#eval", expr, ctx); |
50 |
| - return Promise.resolve(); |
51 |
| - } |
52 |
| - |
53 |
| - dispatch(name: string, fn: string, ...args: unknown[]): Promise<unknown> { |
54 |
| - return this.#denops.dispatch(name, fn, ...args); |
55 |
| - } |
56 |
| -} |
| 1 | +import { Denops } from "../deps.ts"; |
| 2 | +import { gather } from "../batch/mod.ts"; |
| 3 | +import type { GatherHelper } from "../batch/mod.ts"; |
57 | 4 |
|
58 | 5 | /**
|
59 |
| - * Call denops functions sequentially without redraw and return the results. |
60 |
| - * |
61 |
| - * It is a wrapper function of `denops.batch()` to allow users to use `function` |
62 |
| - * modules, `denops.cmd()`, `denops.eval()`, or whatever things which assume a |
63 |
| - * `denops` instance. |
| 6 | + * @deprecated Use `gather()` function in `batch` module instead. |
64 | 7 | */
|
65 | 8 | export async function batch(
|
66 | 9 | denops: Denops,
|
67 |
| - main: (helper: BatchHelper) => Promise<void> | void, |
| 10 | + main: (helper: GatherHelper) => Promise<void> | void, |
68 | 11 | ): Promise<unknown[]> {
|
69 |
| - const helper = new BatchHelper(denops); |
70 |
| - await main(helper); |
71 |
| - const calls = BatchHelper.getCalls(helper); |
72 |
| - return await denops.batch(...calls); |
| 12 | + console.warn( |
| 13 | + "DEPRECATED: Use `gather()` function in `batch` module instead.", |
| 14 | + ); |
| 15 | + return await gather(denops, async (helper: GatherHelper) => { |
| 16 | + return await main(helper); |
| 17 | + }); |
73 | 18 | }
|
74 | 19 |
|
75 |
| -export type { BatchHelper }; |
| 20 | +export type { GatherHelper as BatchHelper }; |
0 commit comments