feat(lib/init): add promise-returned methods of origin async methods

This commit is contained in:
Rintim 2023-11-16 22:15:09 +08:00
parent 4fa9579c7d
commit 595ceb0168
No known key found for this signature in database
GPG Key ID: BE9E1EA615BACFCF
1 changed files with 21 additions and 0 deletions

View File

@ -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('/');