Skip to content

Commit 88660a5

Browse files
committed
perf(REST API): Make REST APIs tree-shakable
Use IIFE to define functions with properties
1 parent 80a0a11 commit 88660a5

File tree

8 files changed

+284
-251
lines changed

8 files changed

+284
-251
lines changed

deno.lock

Lines changed: 161 additions & 158 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rest/getCodeBlock.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,20 @@ export type CodeBlockError =
9292
* @param filename 取得したいコードブロックのファイル名
9393
* @param options オプション
9494
*/
95-
export const getCodeBlock: GetCodeBlock = async (
96-
project,
97-
title,
98-
filename,
99-
options,
100-
) => {
101-
const req = getCodeBlock_toRequest(project, title, filename, options);
102-
const res = await setDefaults(options ?? {}).fetch(req);
103-
return isErr(res) ? res : getCodeBlock_fromResponse(unwrapOk(res));
104-
};
95+
export const getCodeBlock: GetCodeBlock = /* @__PURE__ */ (() => {
96+
const fn: GetCodeBlock = async (
97+
project,
98+
title,
99+
filename,
100+
options,
101+
) => {
102+
const req = getCodeBlock_toRequest(project, title, filename, options);
103+
const res = await setDefaults(options ?? {}).fetch(req);
104+
return isErr(res) ? res : getCodeBlock_fromResponse(unwrapOk(res));
105+
};
106+
107+
fn.toRequest = getCodeBlock_toRequest;
108+
fn.fromResponse = getCodeBlock_fromResponse;
105109

106-
getCodeBlock.toRequest = getCodeBlock_toRequest;
107-
getCodeBlock.fromResponse = getCodeBlock_fromResponse;
110+
return fn;
111+
})();

rest/link.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,19 @@ const getLinks_fromResponse: GetLinks["fromResponse"] = async (response) =>
106106
*
107107
* @param project データを取得したいproject
108108
*/
109-
export const getLinks: GetLinks = async (project, options) => {
110-
const res = await setDefaults(options ?? {}).fetch(
111-
getLinks_toRequest(project, options),
112-
);
113-
if (isErr(res)) return res;
114-
return getLinks_fromResponse(unwrapOk(res));
115-
};
109+
export const getLinks: GetLinks = /* @__PURE__ */ (() => {
110+
const fn: GetLinks = async (project, options) => {
111+
const res = await setDefaults(options ?? {}).fetch(
112+
getLinks_toRequest(project, options),
113+
);
114+
if (isErr(res)) return res;
115+
return getLinks_fromResponse(unwrapOk(res));
116+
};
116117

117-
getLinks.toRequest = getLinks_toRequest;
118-
getLinks.fromResponse = getLinks_fromResponse;
118+
fn.toRequest = getLinks_toRequest;
119+
fn.fromResponse = getLinks_fromResponse;
120+
return fn;
121+
})();
119122

120123
/** 指定したprojectの全てのリンクデータを取得する
121124
*

0 commit comments

Comments
 (0)