From c678b400f8ac292d7c1b355050197a273ec7222c Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Tue, 23 Apr 2024 20:03:53 +0800 Subject: [PATCH] refactor(directive): v-memo --- pages.json | 18 ++++-- .../directive/v-memo/v-memo-composition.uvue | 48 ++++++++++++++ pages/directive/v-memo/v-memo-options.uvue | 53 +++++++++++++++ pages/directive/v-memo/v-memo.test.js | 64 +++++++++---------- pages/directive/v-memo/v-memo.uvue | 38 ----------- pages/index/index.uvue | 46 ++++++++++--- ...ions-API-composition-API-correspondence.md | 4 +- 7 files changed, 183 insertions(+), 88 deletions(-) create mode 100644 pages/directive/v-memo/v-memo-composition.uvue create mode 100644 pages/directive/v-memo/v-memo-options.uvue delete mode 100644 pages/directive/v-memo/v-memo.uvue diff --git a/pages.json b/pages.json index 128c081..ad00c77 100644 --- a/pages.json +++ b/pages.json @@ -214,6 +214,18 @@ "navigationBarTitleText": "v-once 组合式 API" } }, + { + "path": "pages/directive/v-memo/v-memo-options", + "style": { + "navigationBarTitleText": "v-memo 选项式 API" + } + }, + { + "path": "pages/directive/v-memo/v-memo-composition", + "style": { + "navigationBarTitleText": "v-memo 组合式 API" + } + }, // #endif @@ -279,12 +291,6 @@ "navigationBarTitleText": "v-model" } }, - { - "path": "pages/directive/v-memo/v-memo", - "style": { - "navigationBarTitleText": "v-memo" - } - }, { "path": "pages/directive/v-slot/v-slot", "style": { diff --git a/pages/directive/v-memo/v-memo-composition.uvue b/pages/directive/v-memo/v-memo-composition.uvue new file mode 100644 index 0000000..3815199 --- /dev/null +++ b/pages/directive/v-memo/v-memo-composition.uvue @@ -0,0 +1,48 @@ + + + diff --git a/pages/directive/v-memo/v-memo-options.uvue b/pages/directive/v-memo/v-memo-options.uvue new file mode 100644 index 0000000..822fe3e --- /dev/null +++ b/pages/directive/v-memo/v-memo-options.uvue @@ -0,0 +1,53 @@ + + + diff --git a/pages/directive/v-memo/v-memo.test.js b/pages/directive/v-memo/v-memo.test.js index d5bec40..7305fe8 100644 --- a/pages/directive/v-memo/v-memo.test.js +++ b/pages/directive/v-memo/v-memo.test.js @@ -1,4 +1,5 @@ -const PAGE_PATH = '/pages/directive/v-memo/v-memo' +const OPTIONS_PAGE_PATH = '/pages/directive/v-memo/v-memo-options' +const COMPOSITION_PAGE_PATH = '/pages/directive/v-memo/v-memo-composition' describe('v-memo', () => { if (process.env.uniTestPlatformInfo.startsWith('web')) { @@ -9,44 +10,39 @@ describe('v-memo', () => { return } let page - beforeAll(async () => { - page = await program.reLaunch(PAGE_PATH) + const test = async (pagePath) => { + page = await program.reLaunch(pagePath) await page.waitFor('view') - }) - it('basic', async () => { - const equivalentVOnceTextEl = await page.$('.equivalent-v-once-text') - let equivalentVOnceTextText = await equivalentVOnceTextEl.text() - expect(equivalentVOnceTextText).toBe( - 'This will never change: hello world' - ) + + const neverChangeMsg = await page.$('#v-memo-never-change-msg') + expect(await neverChangeMsg.text()).toBe('hello world') - const vMemoTextEl = await page.$('.v-memo-text') - let vMemoTextText = await vMemoTextEl.text() - expect(vMemoTextText).toBe( - 'This will change when num change, msg: hello world, num: 0' - ) + const msg = await page.$('#msg') + expect(await msg.text()).toBe('hello world') + + const numChangeMsg = await page.$('#v-memo-num-change-msg') + expect(await numChangeMsg.text()).toBe('hello world') - const changeMessageBtn = await page.$('.change-message-btn') + const changeMessageBtn = await page.$('#change-message-btn') await changeMessageBtn.tap() - const msg = await page.data('msg') - expect(msg).toBe('msg changed') + expect(await neverChangeMsg.text()).toBe('hello world') + expect(await msg.text()).toBe('msg changed') + expect(await numChangeMsg.text()).toBe('hello world') - equivalentVOnceTextText = await equivalentVOnceTextEl.text() - expect(equivalentVOnceTextText).toBe( - 'This will never change: hello world' - ) - vMemoTextText = await vMemoTextEl.text() - expect(vMemoTextText).toBe( - 'This will change when num change, msg: hello world, num: 0' - ) + const incrementNumBtn = await page.$('#increment-num-btn') + await incrementNumBtn.tap() - const plusNumBtn = await page.$('.plus-num-btn') - await plusNumBtn.tap() - - vMemoTextText = await vMemoTextEl.text() - expect(vMemoTextText).toBe( - 'This will change when num change, msg: msg changed, num: 1' - ) - }) + expect(await neverChangeMsg.text()).toBe('hello world') + expect(await msg.text()).toBe('msg changed') + expect(await numChangeMsg.text()).toBe('msg changed') + } + + it('v-memo options API', async () => { + await test(OPTIONS_PAGE_PATH) + }) + + it('v-memo composition API', async () => { + await test(COMPOSITION_PAGE_PATH) + }) }) diff --git a/pages/directive/v-memo/v-memo.uvue b/pages/directive/v-memo/v-memo.uvue deleted file mode 100644 index 0d64de1..0000000 --- a/pages/directive/v-memo/v-memo.uvue +++ /dev/null @@ -1,38 +0,0 @@ - - - diff --git a/pages/index/index.uvue b/pages/index/index.uvue index 2ce8244..c9b2977 100644 --- a/pages/index/index.uvue +++ b/pages/index/index.uvue @@ -553,18 +553,22 @@ export default { name: 'toRef', url: 'to-ref/to-ref' }, - // #ifdef APP { id: 'to-refs', name: 'toRefs', - url: 'to-refs/to-refs' + url: 'to-refs/to-refs', + // #ifdef WEB + enable: false + // #endif }, { id: 'to-value', name: 'toValue', - url: 'to-value/to-value' - }, + url: 'to-value/to-value', + // #ifdef WEB + enable: false // #endif + }, { id: 'un-ref', name: 'unRef', @@ -720,7 +724,6 @@ export default { name: 'v-pre', url: 'v-pre/v-pre' }, - // #ifdef APP { id: 'v-once', name: 'v-once', @@ -728,16 +731,43 @@ export default { { id: 'v-once-options', name: 'v-once 选项式 API', - url: 'v-once-options' + url: 'v-once-options', + // #ifdef WEB + enable: false + // #endif }, { id: 'v-once-composition', name: 'v-once 组合式 API', - url: 'v-once-composition' + url: 'v-once-composition', + // #ifdef WEB + enable: false + // #endif + }, + ] + }, + { + id: 'v-memo', + name: 'v-memo', + children: [ + { + id: 'v-memo-options', + name: 'v-memo 选项式 API', + url: 'v-memo-options', + // #ifdef WEB + enable: false + // #endif + }, + { + id: 'v-memo-composition', + name: 'v-memo 组合式 API', + url: 'v-memo-composition', + // #ifdef WEB + enable: false + // #endif }, ] }, - // #endif ] }, { diff --git a/refactor_options-API-composition-API-correspondence.md b/refactor_options-API-composition-API-correspondence.md index 2069d65..cdd88db 100644 --- a/refactor_options-API-composition-API-correspondence.md +++ b/refactor_options-API-composition-API-correspondence.md @@ -163,8 +163,8 @@ function transform(fileInfo, api) { - [ ] v-slot - [x] v-pre - [x] v-once -- [ ] v-memo -- [ ] v-text +- [x] v-memo +- [ ] v-text 暂不支持 - [ ] v-cloak 暂不支持 ## lifecycle -- GitLab