From 0ee7ddc6a1d021ba48df2ee8ea556d80f3187248 Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 4 Apr 2023 13:55:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E7=94=BB=E6=96=B9=E6=B3=95=E8=BF=94?= =?UTF-8?q?=E5=9B=9EPromise=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/anim.js | 9 ++++++--- src/html.js | 2 +- src/index.js | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 9409342..b35220e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bd/core", - "version": "1.8.2", + "version": "1.8.3", "type": "module", "description": "百搭UI组件库的核心", "main": "dist/index.js", diff --git a/src/anim.js b/src/anim.js index 7c0d8e3..bf05e40 100644 --- a/src/anim.js +++ b/src/anim.js @@ -13,15 +13,18 @@ export function animate(duration = 200, fromto = [], out = false) { direction: out ? 'reverse' : 'normal', fill: 'forwards' }) - if (out) { + return new Promise(resolve => { res.addEventListener( 'finish', _ => { - this.style.display = 'none' + if (out) { + this.style.display = 'none' + } + resolve() }, { once: true } ) - } + }) } export const MODES = { fade: [{ opacity: 0 }, { opacity: 1 }], diff --git a/src/html.js b/src/html.js index 1582dc6..7ea81a2 100644 --- a/src/html.js +++ b/src/html.js @@ -631,7 +631,7 @@ class AnimPart extends AttributePart { fromto = custom } this.element.$animate = function (out = false) { - animate.call(this, duration, fromto, out) + return animate.call(this, duration, fromto, out) } } } diff --git a/src/index.js b/src/index.js index 79ce5fc..d1d6fc4 100644 --- a/src/index.js +++ b/src/index.js @@ -91,7 +91,7 @@ export class Component extends HTMLElement { Object.defineProperty(this.prototype, '$animate', { value(out) { if (this[__mounted__]) { - animate.call(this, duration, MODES[type], out) + return animate.call(this, duration, MODES[type], out) } }, enumerable: false