From 217b2b738f23ed50faa583f2fa3e574c432c056b Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Sun, 21 Apr 2024 15:16:40 +0800 Subject: [PATCH] refactor(reactivity): getCurrentScope --- pages/index/index.uvue | 5 ++++ .../get-current-scope.test.js | 6 ++-- .../get-current-scope/get-current-scope.uvue | 30 +++++++++++-------- ...ions-API-composition-API-correspondence.md | 2 +- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/pages/index/index.uvue b/pages/index/index.uvue index b98f363..b2af8e4 100644 --- a/pages/index/index.uvue +++ b/pages/index/index.uvue @@ -586,6 +586,11 @@ export default { name: 'effectScope', url: 'effect-scope/effect-scope' }, + { + id: 'get-current-scope', + name: 'getCurrentScope', + url: 'get-current-scope/get-current-scope' + }, ] } ] as Page[] diff --git a/pages/reactivity/advanced/get-current-scope/get-current-scope.test.js b/pages/reactivity/advanced/get-current-scope/get-current-scope.test.js index d1c92fc..91f340e 100644 --- a/pages/reactivity/advanced/get-current-scope/get-current-scope.test.js +++ b/pages/reactivity/advanced/get-current-scope/get-current-scope.test.js @@ -1,4 +1,4 @@ -const PAGE_PATH = '/pages/composition-api/reactivity/get-current-scope/get-current-scope' +const PAGE_PATH = '/pages/reactivity/advanced/get-current-scope/get-current-scope' describe('getCurrentScope', () => { let page = null @@ -8,11 +8,11 @@ describe('getCurrentScope', () => { }) it('basic', async () => { const hasCurrentScope = await page.$('#has-current-scope') - expect(await hasCurrentScope.text()).toBe('hasCurrentScope: false') + expect(await hasCurrentScope.text()).toBe('false') const createScopeBtn = await page.$('#create-scope-btn') await createScopeBtn.tap() - expect(await hasCurrentScope.text()).toBe('hasCurrentScope: true') + expect(await hasCurrentScope.text()).toBe('true') }) }) \ No newline at end of file diff --git a/pages/reactivity/advanced/get-current-scope/get-current-scope.uvue b/pages/reactivity/advanced/get-current-scope/get-current-scope.uvue index c5135c0..942bbc3 100644 --- a/pages/reactivity/advanced/get-current-scope/get-current-scope.uvue +++ b/pages/reactivity/advanced/get-current-scope/get-current-scope.uvue @@ -1,18 +1,22 @@ <template> <view class="page"> - <text id="has-current-scope">hasCurrentScope: {{ hasCurrentScope }}</text> - <button id="create-scope-btn" class="mt-10" @click="createScope">create scope</button> + <view class="flex justify-between flex-row mb-10"> + <text>hasCurrentScope:</text> + <text id="has-current-scope">{{ hasCurrentScope }}</text> + </view> + <button id="create-scope-btn" class="mt-10" @click="createScope"> + create scope + </button> </view> </template> -<script setup> - - const hasCurrentScope = ref(false) - - const createScope = () => { - const scope = effectScope() - scope.run(() => { - hasCurrentScope.value = getCurrentScope() !== null - }) - } -</script> \ No newline at end of file +<script setup lang="uts"> +const hasCurrentScope = ref(false); + +const createScope = () => { + const scope = effectScope(); + scope.run(() => { + hasCurrentScope.value = getCurrentScope() !== null; + }); +}; +</script> diff --git a/refactor_options-API-composition-API-correspondence.md b/refactor_options-API-composition-API-correspondence.md index 15dfa45..5885dc7 100644 --- a/refactor_options-API-composition-API-correspondence.md +++ b/refactor_options-API-composition-API-correspondence.md @@ -142,7 +142,7 @@ function transform(fileInfo, api) { - [x] customRef - [x] effectScope -- [ ] getCurrentScope +- [x] getCurrentScope - [ ] markRaw - [ ] onScopeDispose - [ ] shallowReactive -- GitLab