Skip to content

Commit b7efd7f

Browse files
committed
chore: Add documents
1 parent f98e831 commit b7efd7f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

args_binder.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,41 @@ import type { Detail } from "./item.ts";
55
import { defineSource, type Source } from "./source.ts";
66
import { type Curator, defineCurator } from "./curator.ts";
77

8+
/**
9+
* A type that represents a list of strings or a function which gets a denops
10+
* instance and returns a list of strings.
11+
*/
812
type BoundArgsProvider =
913
| string[]
1014
| ((denops: Denops) => string[] | Promise<string[]>);
1115

16+
/**
17+
* Get the value to be passed to the source as args with resolving it when it
18+
* is a function.
19+
*
20+
* @param denops - A denops instance.
21+
* @param args - A list of strings or a function that returns it.
22+
* @return The resolved value of `args`.
23+
*/
1224
async function deriveBoundArgs(
1325
denops: Denops,
1426
args: BoundArgsProvider,
1527
): Promise<string[]> {
1628
return args instanceof Function ? await args(denops) : args;
1729
}
1830

31+
/**
32+
* Creates a new source from an existing source with fixing some args.
33+
*
34+
* `args` is passed to the source as the head n number of arguments. The
35+
* command-line arguments follow them. `args` is used as is if it is a list of
36+
* strings. Otherwise, when it is a function, it is evaluated each time when
37+
* the source is called, and the resulting value is passed to the base source.
38+
*
39+
* @param baseSource - The source to fix args.
40+
* @param args - The args to pass to the source.
41+
* @return A single source which calls the given source with given args.
42+
*/
1943
export function bindSourceArgs<T extends Detail = Detail>(
2044
baseSource: Derivable<Source<T>>,
2145
args: BoundArgsProvider,
@@ -35,6 +59,19 @@ export function bindSourceArgs<T extends Detail = Detail>(
3559
});
3660
}
3761

62+
/**
63+
* Creates a new curator from an existing curator with fixing some args.
64+
*
65+
* `args` is passed to the curator as the head n number of arguments. The
66+
* command-line arguments follow them. `args` is used as is if it is a list of
67+
* strings. Otherwise, when it is a function, it is evaluated each time when
68+
* the curator is called, and the resulting value is passed to the base
69+
* curator.
70+
*
71+
* @param baseSource - The curator to fix args.
72+
* @param args - The args to pass to the curator.
73+
* @return A single curator which calls the given curator with given args.
74+
*/
3875
export function bindCuratorArgs<T extends Detail = Detail>(
3976
baseCurator: Derivable<Curator<T>>,
4077
args: BoundArgsProvider,

0 commit comments

Comments
 (0)