Merge pull request #647 from nofficalfs/PR-InitJsPromise
Add Promise-Async Methods for parts of `lib.init`
This commit is contained in:
commit
f56a1c2b78
57
game/game.js
57
game/game.js
|
@ -8437,6 +8437,63 @@
|
|||
}
|
||||
},
|
||||
init:{
|
||||
/**
|
||||
* 部分函数的Promise版本
|
||||
*/
|
||||
promises:{
|
||||
/**
|
||||
* Promise版的`lib.init.js`
|
||||
*
|
||||
* @param {string} path - 文件路径
|
||||
* @param {string | string[]} [file] - 文件名或文件名组,忽略则直接读取`path`的内容
|
||||
* @returns {Promise<Event>}
|
||||
*/
|
||||
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<HTMLLinkElement>}
|
||||
*/
|
||||
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<ProgressEvent>}
|
||||
*/
|
||||
req:(str,master)=>new Promise((resolve,reject)=>lib.init.req(str,resolve,reject,master)),
|
||||
|
||||
/**
|
||||
* Promise版的`lib.init.json`
|
||||
*
|
||||
* @param {string} url - 要读取的地址
|
||||
* @returns {Promise<object>}
|
||||
*/
|
||||
json:(url)=>new Promise((resolve,reject)=>lib.init.json(url,resolve,reject)),
|
||||
|
||||
/**
|
||||
* Promise版的`lib.init.sheet`
|
||||
*
|
||||
* @returns {Promise<HTMLStyleElement>}
|
||||
*/
|
||||
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('/');
|
||||
|
|
Loading…
Reference in New Issue