From 595ceb0168cc8b5d9bfba57522f7ca14a9b60ab7 Mon Sep 17 00:00:00 2001 From: Rintim Date: Thu, 16 Nov 2023 22:15:09 +0800 Subject: [PATCH] feat(lib/init): add promise-returned methods of origin async methods --- game/game.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/game/game.js b/game/game.js index 2e298f74a..a6409cec3 100644 --- a/game/game.js +++ b/game/game.js @@ -8375,6 +8375,27 @@ } }, init:{ + // Promise Method + promises:{ + /** + * Promise版的`lib.init.js` + */ + js:(path,file)=>new Promise((resolve,reject)=>lib.init.js(path,file,resolve,reject)), + 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); + }), + 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)), + sheet(){ + return new Promise((resolve,reject)=>{ + const style=lib.init.sheet.apply(lib.init,arguments); + style.addEventListener("load",()=>resolve(style)); + style.addEventListener("error",reject); + }) + } + }, init:function(){ if(typeof __dirname==='string'&&__dirname.length){ var dirsplit=__dirname.split('/');