Skip to content

Commit b57537e

Browse files
committed
💪 Use collect() instead of gather()
1 parent d7e8feb commit b57537e

File tree

1 file changed

+20
-33
lines changed

1 file changed

+20
-33
lines changed

denops_std/buffer/buffer.ts

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts";
22
import * as autocmd from "../autocmd/mod.ts";
33
import * as batch from "../batch/mod.ts";
44
import * as fn from "../function/mod.ts";
5+
import * as op from "../option/mod.ts";
56
import { execute } from "../helper/mod.ts";
6-
import * as unknownutil from "https://deno.land/x/unknownutil@v2.1.0/mod.ts";
77
import {
8-
assertFileFormat,
98
FileFormat,
109
findFileFormat,
11-
isFileFormat,
1210
maybeFileFormat,
1311
splitText,
1412
} from "./fileformat.ts";
@@ -268,21 +266,16 @@ export async function decode(
268266
data: Uint8Array,
269267
options: DecodeOptions = {},
270268
): Promise<DecodeResult> {
271-
const [fileformat, fileformatsStr, fileencodingsStr] = await batch.gather(
269+
const [fileformat, fileformatsStr, fileencodingsStr] = await batch.collect(
272270
denops,
273-
async (denops) => {
274-
await fn.getbufvar(denops, bufnr, "&fileformat");
275-
await fn.getbufvar(denops, bufnr, "&fileformats");
276-
await fn.getbufvar(denops, bufnr, "&fileencodings");
277-
},
271+
(denops) => [
272+
op.fileformat.getBuffer(denops, bufnr) as Promise<FileFormat>,
273+
op.fileformats.get(denops),
274+
op.fileencodings.get(denops),
275+
],
278276
);
279-
assertFileFormat(fileformat);
280-
unknownutil.assertString(fileformatsStr);
281-
unknownutil.assertString(fileencodingsStr);
282-
const fileformats = fileformatsStr.split(",");
277+
const fileformats = fileformatsStr.split(",") as FileFormat[];
283278
const fileencodings = fileencodingsStr.split(",");
284-
unknownutil.assertArray(fileformats, isFileFormat);
285-
unknownutil.assertArray(fileencodings, unknownutil.isString);
286279
let enc: string;
287280
let text: string;
288281
if (options.fileencoding) {
@@ -478,17 +471,14 @@ export async function ensure<T>(
478471
bufnr: number,
479472
executor: () => T,
480473
): Promise<T> {
481-
const [bufnrCur, winidCur, winidNext] = await batch.gather(
474+
const [bufnrCur, winidCur, winidNext] = await batch.collect(
482475
denops,
483-
async (denops) => {
484-
await fn.bufnr(denops);
485-
await fn.win_getid(denops);
486-
await fn.bufwinid(denops, bufnr);
487-
},
476+
(denops) => [
477+
fn.bufnr(denops),
478+
fn.win_getid(denops),
479+
fn.bufwinid(denops, bufnr),
480+
],
488481
);
489-
unknownutil.assertNumber(bufnrCur);
490-
unknownutil.assertNumber(winidCur);
491-
unknownutil.assertNumber(winidNext);
492482
if (winidCur === winidNext) {
493483
return executor();
494484
}
@@ -532,17 +522,14 @@ export async function modifiable<T>(
532522
bufnr: number,
533523
executor: () => T,
534524
): Promise<T> {
535-
const [modified, modifiable, foldmethod] = await batch.gather(
525+
const [modified, modifiable, foldmethod] = await batch.collect(
536526
denops,
537-
async (denops) => {
538-
await fn.getbufvar(denops, bufnr, "&modified");
539-
await fn.getbufvar(denops, bufnr, "&modifiable");
540-
await fn.getbufvar(denops, bufnr, "&foldmethod");
541-
},
527+
(denops) => [
528+
op.modified.getBuffer(denops, bufnr),
529+
op.modifiable.getBuffer(denops, bufnr),
530+
op.foldmethod.getBuffer(denops, bufnr),
531+
],
542532
);
543-
unknownutil.assertNumber(modified);
544-
unknownutil.assertNumber(modifiable);
545-
unknownutil.assertString(foldmethod);
546533
await batch.batch(denops, async (denops) => {
547534
await fn.setbufvar(denops, bufnr, "&modifiable", 1);
548535
await fn.setbufvar(denops, bufnr, "&foldmethod", "manual");

0 commit comments

Comments
 (0)