Skip to content

Commit a9860a0

Browse files
committed
📝 Rewrite root mod.ts to follow the latest best practice
1 parent 8a27175 commit a9860a0

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

denops_std/mod.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* ```typescript
1010
* import { Denops } from "./mod.ts";
11+
* import * as batch from "./batch/mod.ts";
1112
* import * as fn from "./function/mod.ts";
1213
* import * as vars from "./variable/mod.ts";
1314
* import * as helper from "./helper/mod.ts";
@@ -16,11 +17,19 @@
1617
*
1718
* export async function main(denops: Denops): Promise<void> {
1819
* denops.dispatcher = {
20+
* async init(): Promise<void> {
21+
* // This is just an example. Developers usually should define commands directly in Vim script.
22+
* await batch.batch(denops, async (denops) => {
23+
* await denops.cmd(`command! HelloWorld call denops#notify("${denops.name}", "say", ["World"])`);
24+
* await denops.cmd(`command! HelloDenops call denops#notify("${denops.name}", "say", ["Denops"])`);
25+
* });
26+
* },
1927
* async say(where: unknown): Promise<void> {
2028
* assert(where, is.String);
21-
*
22-
* const name = await fn.input(denops, "Your name: ");
23-
* const progname = await vars.v.get(denops, "progname");
29+
* const [name, progname] = await batch.collect(denops, (denops) => [
30+
* fn.input(denops, "Your name: "),
31+
* vars.v.get(denops, "progname"),
32+
* ]);
2433
* const messages = [
2534
* `Hello ${where}.`,
2635
* `Your name is ${name}.`,
@@ -29,17 +38,12 @@
2938
* await helper.echo(denops, messages.join("\n"));
3039
* },
3140
* };
32-
*
33-
* await helper.execute(
34-
* denops,
35-
* `
36-
* command! HelloWorld call denops#notify("${denops.name}", "say", ["World"])
37-
* command! HelloDenops call denops#notify("${denops.name}", "say", ["Denops"])
38-
* `,
39-
* );
4041
* }
4142
* ```
4243
*
44+
* Note that developers should avoid calling initialization code within the `main` function.
45+
* If necessary, add an `init` API or a similar approach like above and call it from `plugin/<your_plugin>.vim`.
46+
*
4347
* See [Denops Documentation](https://vim-denops.github.io/denops-documentation/)
4448
* or [denops-helloworld.vim](https://github.com/vim-denops/denops-helloworld.vim)
4549
* for more details.

0 commit comments

Comments
 (0)