From 0d9e0d5cb8c842371e05b56b2904efd9922d8578 Mon Sep 17 00:00:00 2001 From: hdx Date: Fri, 19 Apr 2024 15:14:59 +0800 Subject: [PATCH] =?UTF-8?q?feat($off):=20=E6=94=AF=E6=8C=81=E7=AC=AC?= =?UTF-8?q?=E4=BA=8C=E4=B8=AA=E5=8F=82=E6=95=B0=E4=B8=BA=E5=8F=AF=E9=80=89?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E4=BC=A0=E9=80=92=E6=97=B6=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E8=AF=A5=E4=BA=8B=E4=BB=B6=E7=9A=84=E6=89=80=E6=9C=89=E7=9B=91?= =?UTF-8?q?=E5=90=AC=E5=92=8C=20Web/iOS=20=E4=BF=9D=E6=8C=81=E4=B8=80?= =?UTF-8?q?=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/event-bus/event-bus.test.js | 30 +++++++++++++-------------- pages/API/event-bus/event-bus.uvue | 3 +-- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pages/API/event-bus/event-bus.test.js b/pages/API/event-bus/event-bus.test.js index b0b61183..bf58ee9d 100644 --- a/pages/API/event-bus/event-bus.test.js +++ b/pages/API/event-bus/event-bus.test.js @@ -52,21 +52,21 @@ describe('event-bus', () => { expect(l3).toBe(0) }) - // it('off-all', async () => { - // await page.callMethod('clear') - // await page.callMethod('on') - // await page.callMethod('on2') - // await page.callMethod('emit') - // const l1 = (await page.data()).log.length - // expect(l1).toBe(2) + it('off-all', async () => { + await page.callMethod('clear') + await page.callMethod('on') + await page.callMethod('on2') + await page.callMethod('emit') + const l1 = (await page.data()).log.length + expect(l1).toBe(2) - // await page.callMethod('clear') - // const l2 = (await page.data()).log.length - // expect(l2).toBe(0) + await page.callMethod('clear') + const l2 = (await page.data()).log.length + expect(l2).toBe(0) - // await page.callMethod('offAll') - // await page.callMethod('emit') - // const l3 = (await page.data()).log.length - // expect(l3).toBe(0) - // }) + await page.callMethod('offAll') + await page.callMethod('emit') + const l3 = (await page.data()).log.length + expect(l3).toBe(0) + }) }) diff --git a/pages/API/event-bus/event-bus.uvue b/pages/API/event-bus/event-bus.uvue index b470400e..a34651a7 100644 --- a/pages/API/event-bus/event-bus.uvue +++ b/pages/API/event-bus/event-bus.uvue @@ -48,8 +48,7 @@ uni.$off('test', this.fn) }, offAll() { - // TODO 第二个参数为可选,后续优化后可不传递 - //uni.$off('test', null) + uni.$off('test') }, emit() { uni.$emit('test', 'msg:' + Date.now()) -- GitLab