Skip to main content
Module

x/denops_std/anonymous/mod.ts>add

📚 Standard module for denops.vim
Go to Latest
function add
import { add } from "https://deno.land/x/denops_std@v3.12.2/anonymous/mod.ts";

Add anonymous functions as denops API and return the identifiers

import { Denops } from "../mod.ts";
import * as anonymous from "./mod.ts";

export async function main(denops: Denops): Promise<void> {
  // Add anonymous functions
  const ids = anonymous.add(
    denops,
    () => {
      // Do what ever you want.
    },
    () => {
      // Do what ever you want.
    },
    // You can add as many callbacks as you want...
  );

  // Use ids to dispatch added functions from Deno
  await denops.dispatch(denops.name, ids[0]);
  await denops.dispatch(denops.name, ids[1]);

  // Or from Vim
  await denops.cmd("call denops#notify(name, id, [])", {
    name: denops.name,
    id: ids[1],
  });
}

Type Parameters

N extends number

Parameters

denops: Denops
...callbacks: Callback[] & { length: N; }