fix(plugin): beforeunload call error if it not exist & bump libs version

pull/2214/head
charlie 2021-06-16 14:47:22 +08:00 committed by Tienson Qin
parent a7cc751269
commit 80e47bf829
3 changed files with 5 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@logseq/libs",
"version": "0.0.1-alpha.18",
"version": "0.0.1-alpha.19",
"description": "Logseq SDK libraries",
"main": "dist/lsplugin.user.js",
"typings": "index.d.ts",

View File

@ -77,6 +77,7 @@ class LSPluginCaller extends EventEmitter {
},
[LSPMSG_BEFORE_UNLOAD]: async (e) => {
debugger
const actor = deferred(10 * 1000)
caller.emit('beforeunload', Object.assign({ actor }, e))
await actor.promise
@ -225,7 +226,7 @@ class LSPluginCaller extends EventEmitter {
this._callUserModel = async (type, payload: any) => {
if (type.startsWith(FLAG_AWAIT)) {
// TODO: attach payload
// TODO: attach payload with method call
return await refChild.get(type.replace(FLAG_AWAIT, ''))
} else {
refChild.call(type, payload)

View File

@ -155,14 +155,13 @@ export class LSPluginUser extends EventEmitter<LSPluginUserEvents> implements IL
_caller.on('beforeunload', async (payload) => {
const { actor, ...rest } = payload
const cb = this._beforeunloadCallback
if (!cb || !actor) return
try {
cb && await cb(rest)
actor.resolve(null)
actor?.resolve(null)
} catch (e) {
console.debug(`${_caller.debugTag} [beforeunload] `, e)
actor.reject(e)
actor?.reject(e)
}
})
}