From f09377e5a5f539d09ef99f92c1c60e7b3fe87214 Mon Sep 17 00:00:00 2001 From: Ansolve Date: Thu, 16 Nov 2023 22:30:06 +0800 Subject: [PATCH] docs(lib/init): add docs for `lib.init.promises`. --- game/game.js | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/game/game.js b/game/game.js index a6409cec3..fa85ea5a7 100644 --- a/game/game.js +++ b/game/game.js @@ -8375,19 +8375,56 @@ } }, init:{ - // Promise Method + /** + * 部分函数的Promise版本 + */ promises:{ /** * Promise版的`lib.init.js` + * + * @param {string} path - 文件路径 + * @param {string | string[]} [file] - 文件名或文件名组,忽略则直接读取`path`的内容 + * @returns {Promise} */ js:(path,file)=>new Promise((resolve,reject)=>lib.init.js(path,file,resolve,reject)), + + /** + * Promise版的`lib.init.css` + * + * @param {string} path - 文件路径 + * @param {string | string[]} [file] - 文件名或文件名组,忽略则直接读取`path`的内容 + * @param {Element} [before] 新样式dom的位置 + * @returns {Promise} + */ css:(path,file,before)=>new Promise((resolve,reject)=>{ const style=lib.init.css(path,file,before); style.addEventListener("load",()=>resolve(style)); style.addEventListener("error",reject); }), + + /** + * Promise版的`lib.init.req` + * + * @param {string} str - 要读取的地址 + * @param {string} [master] + * @returns {Promise} + */ req:(str,master)=>new Promise((resolve,reject)=>lib.init.req(str,resolve,reject,master)), - json:(url)=>new Promise((resolve,reject)=>lib.init.js(url,resolve,reject)), + + /** + * Promise版的`lib.init.req` + * + * @param {string} str - 要读取的地址 + * @param {string} [master] + * @returns {Promise} + */ + json:(url)=>new Promise((resolve,reject)=>lib.init.json(url,resolve,reject)), + + /** + * Promise版的`lib.init.sheet` + * + * @returns {Promise} + */ sheet(){ return new Promise((resolve,reject)=>{ const style=lib.init.sheet.apply(lib.init,arguments);