Skip to content

Commit fb218f4

Browse files
committed
👍 Sharing same helper functions between different versions
Closes #191
1 parent 5759940 commit fb218f4

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

denops_std/buffer/buffer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import {
1515
import { tryDecode } from "./fileencoding.ts";
1616
import { generateUniqueString } from "../util.ts";
1717

18-
const cacheKey = Symbol("denops_std/buffer/buffer.ts");
19-
const suffix = generateUniqueString();
18+
const cacheKey = "denops_std/buffer/buffer.ts@1";
2019

2120
async function ensurePrerequisites(denops: Denops): Promise<string> {
22-
if (cacheKey in denops.context) {
23-
return suffix;
21+
if (typeof denops.context[cacheKey] === "string") {
22+
return denops.context[cacheKey];
2423
}
25-
denops.context[cacheKey] = true;
24+
const suffix = generateUniqueString();
25+
denops.context[cacheKey] = suffix;
2626
const script = `
2727
function! DenopsStdBufferOpen_${suffix}(bang, mods, opener, cmdarg, bufname) abort
2828
execute printf('%s %s%s %s \`=a:bufname\`', a:mods, a:opener, a:bang ? '!' : '', a:cmdarg)

denops_std/function/getreginfo.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { lt } from "https://deno.land/std@0.171.0/semver/mod.ts";
33
import { execute } from "../helper/mod.ts";
44
import { generateUniqueString } from "../util.ts";
55

6-
const cacheKey = Symbol("denops_std/function/getreginfo.ts");
7-
const suffix = generateUniqueString();
6+
const cacheKey = "denops_std/function/getreginfo.ts@1";
87

98
async function ensurePrerequisites(denops: Denops): Promise<string> {
10-
if (cacheKey in denops.context) {
11-
return suffix;
9+
if (typeof denops.context[cacheKey] === "string") {
10+
return denops.context[cacheKey];
1211
}
13-
denops.context[cacheKey] = true;
12+
const suffix = generateUniqueString();
13+
denops.context[cacheKey] = suffix;
1414
const script = `
1515
function! DenopsStdFunctionGetreginfo_${suffix}(...) abort
1616
let l:result = call('getreginfo', a:000)

denops_std/helper/echo.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts";
22
import { execute } from "./execute.ts";
33
import { generateUniqueString } from "../util.ts";
44

5-
const cacheKey = Symbol("denops_std/helper/echo");
5+
const cacheKey = "denops_std/helper/echo@1";
66
const cacheKeySilent = "denops_std/helper/echo/silent@1";
7-
const suffix = generateUniqueString();
87

98
async function ensurePrerequisites(denops: Denops): Promise<string> {
10-
if (cacheKey in denops.context) {
11-
return suffix;
9+
if (typeof denops.context[cacheKey] === "string") {
10+
return denops.context[cacheKey];
1211
}
13-
denops.context[cacheKey] = true;
12+
const suffix = generateUniqueString();
13+
denops.context[cacheKey] = suffix;
1414
const script = `
1515
let g:loaded_denops_std_helper_echo_${suffix} = 1
1616
let s:denops_std_helper_echo_timer = 0

denops_std/helper/input.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import * as anonymous from "../anonymous/mod.ts";
88
import { execute } from "./execute.ts";
99
import { generateUniqueString } from "../util.ts";
1010

11-
const cacheKey = Symbol("denops_std/helper/input");
12-
const suffix = generateUniqueString();
11+
const cacheKey = "denops_std/helper/input@1";
1312

1413
async function ensurePrerequisites(denops: Denops): Promise<string> {
15-
if (cacheKey in denops.context) {
16-
return suffix;
14+
if (typeof denops.context[cacheKey] === "string") {
15+
return denops.context[cacheKey];
1716
}
18-
denops.context[cacheKey] = true;
17+
const suffix = generateUniqueString();
18+
denops.context[cacheKey] = suffix;
1919
const script = `
2020
let s:loaded_denops_std_helper_input_${suffix} = 1
2121

0 commit comments

Comments
 (0)