提交 217b2b73 编写于 作者: DCloud-WZF's avatar DCloud-WZF :speech_balloon:

refactor(reactivity): getCurrentScope

上级 e3a4ded2
...@@ -586,6 +586,11 @@ export default { ...@@ -586,6 +586,11 @@ export default {
name: 'effectScope', name: 'effectScope',
url: 'effect-scope/effect-scope' url: 'effect-scope/effect-scope'
}, },
{
id: 'get-current-scope',
name: 'getCurrentScope',
url: 'get-current-scope/get-current-scope'
},
] ]
} }
] as Page[] ] as Page[]
......
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', () => { describe('getCurrentScope', () => {
let page = null let page = null
...@@ -8,11 +8,11 @@ describe('getCurrentScope', () => { ...@@ -8,11 +8,11 @@ describe('getCurrentScope', () => {
}) })
it('basic', async () => { it('basic', async () => {
const hasCurrentScope = await page.$('#has-current-scope') 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') const createScopeBtn = await page.$('#create-scope-btn')
await createScopeBtn.tap() await createScopeBtn.tap()
expect(await hasCurrentScope.text()).toBe('hasCurrentScope: true') expect(await hasCurrentScope.text()).toBe('true')
}) })
}) })
\ No newline at end of file
<template> <template>
<view class="page"> <view class="page">
<text id="has-current-scope">hasCurrentScope: {{ hasCurrentScope }}</text> <view class="flex justify-between flex-row mb-10">
<button id="create-scope-btn" class="mt-10" @click="createScope">create scope</button> <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> </view>
</template> </template>
<script setup> <script setup lang="uts">
const hasCurrentScope = ref(false);
const hasCurrentScope = ref(false)
const createScope = () => { const createScope = () => {
const scope = effectScope() const scope = effectScope();
scope.run(() => { scope.run(() => {
hasCurrentScope.value = getCurrentScope() !== null hasCurrentScope.value = getCurrentScope() !== null;
}) });
} };
</script> </script>
...@@ -142,7 +142,7 @@ function transform(fileInfo, api) { ...@@ -142,7 +142,7 @@ function transform(fileInfo, api) {
- [x] customRef - [x] customRef
- [x] effectScope - [x] effectScope
- [ ] getCurrentScope - [x] getCurrentScope
- [ ] markRaw - [ ] markRaw
- [ ] onScopeDispose - [ ] onScopeDispose
- [ ] shallowReactive - [ ] shallowReactive
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部