Merge pull request #254 from nonameShijian/PR-Branch

lib.onload支持传入GeneratorFunction以解决需要异步函数的问题。修复制作扩展的函数被懒加载的问题以及回滚deleteDB函数
This commit is contained in:
Spmario233 2023-09-03 20:52:22 +08:00 committed by GitHub
commit 8cdc7a4b62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 47 additions and 7 deletions

View File

@ -29,6 +29,36 @@
}
}
}
function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){
try{
var info=gen[key](arg);
var value=info.value;
}catch(error){
reject(error);
return;
}
if(info.done){
resolve(value);
}else{
Promise.resolve(value).then(_next,_throw);
}
}
function _asyncToGenerator(fn){
return function(){
var self=this,args=arguments;
return new Promise(function(resolve, reject){
var gen=fn.apply(self,args);
function _next(value){
asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);
}
function _throw(err){
asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);
}
_next(undefined);
});
};
}
const GeneratorFunction=(function*(){}).constructor;
const _status={
paused:false,
paused2:false,
@ -8791,11 +8821,17 @@
}
}
},
onload:function(){
//lib.onload支持传入GeneratorFunction以解决异步函数的问题 by诗笺
onload:_asyncToGenerator(function*(){
const libOnload=lib.onload;
delete lib.onload;
while(libOnload.length){
libOnload.shift()();
while(Array.isArray(libOnload)&&libOnload.length){
const fun=libOnload.shift();
if(fun instanceof GeneratorFunction){
yield _asyncToGenerator(fun)();
}else{
fun();
}
}
ui.updated();
game.documentZoom=game.deviceZoom;
@ -9554,7 +9590,7 @@
}
localStorage.removeItem(lib.configprefix+'directstart');
delete lib.init.init;
},
}),
startOnline:function(){
'step 0'
event._resultid=null;
@ -38547,10 +38583,9 @@
lib[_status.dburgent?'ondb2':'ondb'].push(['deleteDB',Array.from(arguments)]);
return;
}
const store=lib.db.transaction([type],'readwrite').objectStore(type);
if(arguments.length!=1){
if(arguments.length>1){
lib.status.reload++;
store.delete(id).onsuccess=function(){
lib.db.transaction([type],'readwrite').objectStore(type).delete(id).onsuccess=function(){
if(callback) callback.apply(this,arguments);
game.reload2();
};
@ -38559,6 +38594,7 @@
game.getDB(type,null,obj=>{
const objKeys=Object.keys(obj);
lib.status.reload+=objKeys.length;
const store=lib.db.transaction([type],'readwrite').objectStore(type);
objKeys.forEach(value=>store.delete(value).onsuccess=game.reload2);
game.reload2();
});
@ -42329,6 +42365,10 @@
var page=ui.create.div('#create-extension');
var node=ui.create.div('.menubutton.large','制作扩展',start.firstChild,clickMode);
node.mode='create';
game.editExtension=function(name){
node._initLink();
game.editExtension(name);
};
node._initLink=function(){
node.link=page;
var pageboard=ui.create.div(page);