Skip to content

Commit ce6fe13

Browse files
committed
📝 Improve documentation for lambda module
Improved English wording and added documentation for undocumented public APIs in the `lambda` module.
1 parent 5f8e7f4 commit ce6fe13

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

lambda/mod.ts

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
/**
2-
* A module to provide lambda function that is callable from the outside of the plugin.
2+
* A module to provide lambda functions that is callable from outside of the plugin.
33
*
4-
* Use `denops#callback#register()` and `denops#callback#call()` functions instead if you'd like
5-
* to create a lambda function of Vim script that is callable from Deno.
4+
* If you want to create a Vim script lambda functions callable from Deno,
5+
* use `denops#callback#register()` and `denops#callback#call()` instead.
66
*
77
* ```typescript
88
* import type { Entrypoint } from "jsr:@denops/std";
99
* import * as lambda from "jsr:@denops/std/lambda";
1010
*
1111
* export const main: Entrypoint = async (denops) => {
12-
* // Add lambda function
12+
* // Add a lambda function
1313
* const lo = lambda.add(
1414
* denops,
1515
* () => {
1616
* // Do what ever you want.
1717
* },
1818
* );
1919
*
20-
* // Use id to dispatch added function from Deno
20+
* // Dispatch the function from Deno using its id
2121
* await denops.dispatch(denops.name, lo.id);
2222
*
23-
* // Or from Vim
23+
* // Or call it from Vim
2424
* await denops.cmd(`call ${lo.notify()}`);
2525
*
2626
* // Dispose the lambda object
@@ -41,58 +41,58 @@ import { stringify } from "../eval/stringify.ts";
4141
import { expr, type Expression } from "../eval/expression.ts";
4242

4343
/**
44-
* Lambda function identifier
44+
* A unique identifier for a registered lambda function.
4545
*/
4646
export type Identifier = string;
4747

4848
/**
49-
* Lambda function
49+
* The type signature for a lambda function.
5050
*/
5151
export type Fn = (...args: unknown[]) => unknown;
5252

5353
/**
54-
* Register options
54+
* Options for registering a lambda function.
5555
*/
5656
export interface Options {
57-
/** Register the function as a one-time lambda function that will be removed when the function has called */
57+
/** If true, the lambda function will be unregistered when it is called once */
5858
once?: boolean;
5959
}
6060

6161
/**
62-
* Register a lambda function as a denops API and return the identifier.
62+
* Registers a lambda function as a denops API and returns its identifier
6363
*
6464
* ```typescript
6565
* import type { Entrypoint } from "jsr:@denops/std";
6666
* import * as lambda from "jsr:@denops/std/lambda";
6767
*
6868
* export const main: Entrypoint = async (denops) => {
69-
* // Add lambda function
69+
* // Add a lambda function
7070
* const id = lambda.register(
7171
* denops,
7272
* () => {
7373
* // Do what ever you want.
7474
* },
7575
* );
7676
*
77-
* // Use id to dispatch added function from Deno
77+
* // Dispatch the function from Deno using its id
7878
* await denops.dispatch(denops.name, id);
7979
*
80-
* // Or from Vim
80+
* // Or call it from Vim
8181
* await denops.cmd("call denops#notify(name, id, [])", {
8282
* name: denops.name,
8383
* id,
8484
* });
8585
* }
8686
* ```
8787
*
88-
* If you need an one-time lambda function, use `once` option like
88+
* To register a lambda function that is executed only once, use the {@linkcode Options.once|once} option:
8989
*
9090
* ```typescript
9191
* import type { Entrypoint } from "jsr:@denops/std";
9292
* import * as lambda from "jsr:@denops/std/lambda";
9393
*
9494
* export const main: Entrypoint = async (denops) => {
95-
* // Add lambda function
95+
* // Add a lambda function
9696
* const id = lambda.register(
9797
* denops,
9898
* () => {
@@ -103,7 +103,7 @@ export interface Options {
103103
* },
104104
* );
105105
*
106-
* // Use id to dispatch added function from Deno
106+
* // Dispatch the function from Deno using its id
107107
* await denops.dispatch(denops.name, id);
108108
*
109109
* // Second call would throw error
@@ -135,9 +135,9 @@ export function register(
135135
}
136136

137137
/**
138-
* Unregister a lambda function from a denops API identified by the identifier
138+
* Unregisters a lambda function registered via {@linkcode register} function using its identifier
139139
*
140-
* It returns `true` if the lambda function is unregistered. Otherwise it returns `false`.
140+
* Returns `true` if successfully unregistered, otherwise `false`.
141141
*/
142142
export function unregister(
143143
denops: Denops,
@@ -150,11 +150,19 @@ export function unregister(
150150
return false;
151151
}
152152

153+
/**
154+
* An object representing a registered lambda function in the denops API
155+
*
156+
* Instances of this interface are returned by {@linkcode add} function.
157+
*/
153158
export interface Lambda extends Disposable {
159+
/**
160+
* The identifier of the registered lambda function
161+
*/
154162
readonly id: Identifier;
155163

156164
/**
157-
* Create a Vim script expression to notify the lambda function
165+
* Generates a Vim script expression to notify the lambda function
158166
*
159167
* ```typescript
160168
* import type { Entrypoint } from "jsr:@denops/std";
@@ -171,7 +179,7 @@ export interface Lambda extends Disposable {
171179
notify(...args: unknown[]): Expression;
172180

173181
/**
174-
* Create a Vim script expression to request the lambda function
182+
* Generates a Vim script expression to request the lambda function
175183
*
176184
* ```typescript
177185
* import type { Entrypoint } from "jsr:@denops/std";
@@ -188,7 +196,7 @@ export interface Lambda extends Disposable {
188196
request(...args: unknown[]): Expression;
189197

190198
/**
191-
* Dispose the lambda function
199+
* Disposes the lambda function
192200
*
193201
* ```typescript
194202
* import type { Entrypoint } from "jsr:@denops/std";
@@ -198,23 +206,28 @@ export interface Lambda extends Disposable {
198206
* const a = lambda.add(denops, () => {
199207
* // Do what ever you want.
200208
* });
201-
* // Dispose the lambda function manually
202-
* a.dispose();
209+
* // Dispose the lambda function manually
210+
* a.dispose();
203211
* }
204212
* ```
205213
*/
206214
dispose(): void;
207215
}
208216

209217
/**
210-
* Add a lambda function to a denops API and return the lambda object
218+
* Adds a lambda function as a denops API and returns a {@linkcode Lambda} object
219+
*
220+
* The returned {@linkcode Lambda} object provides methods to generate Vim script expressions for
221+
* invoking the registered lambda function, either as a {@linkcode Lambda.notify|notify} or as
222+
* a {@linkcode Lambda.request|request}. It also provides a method to {@linkcode Lambda.dispose|dispose}
223+
* the lambda function.
211224
*
212225
* ```typescript
213226
* import type { Entrypoint } from "jsr:@denops/std";
214227
* import * as lambda from "jsr:@denops/std/lambda";
215228
*
216229
* export const main: Entrypoint = async (denops) => {
217-
* // Add lambda function
230+
* // Add a lambda function
218231
* const lo = lambda.add(
219232
* denops,
220233
* () => {
@@ -230,9 +243,12 @@ export interface Lambda extends Disposable {
230243
* }
231244
* ```
232245
*
233-
* You can pass JSON serializable values, {@linkcode Expression} or
234-
* {@linkcode [eval].RawString|RawString} for {@linkcode [lambda].notify|notify}
235-
* or {@linkcode [lambda].request|request} arguments.
246+
* The {@linkcode Lambda.notify|notify} and {@linkcode Lambda.request|request} methods accept JSON
247+
* serializable values, {@linkcode [eval].Expression|Expression} or {@linkcode [eval].RawString|RawString}
248+
* as arguments. The registered lambda function will be invoked with the arguments.
249+
*
250+
* The lambda function itself can return any of the serializable values as described above.
251+
* The return value will be sent back to Vim when using {@linkcode Lambda.request|request}.
236252
*
237253
* ```typescript
238254
* import type { Denops } from "jsr:@denops/std";

0 commit comments

Comments
 (0)