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

refactor(reactivity): onScopeDispose

上级 44808b41
......@@ -597,6 +597,11 @@ export default {
url: 'mark-raw/mark-raw',
enable: false
},
{
id: 'on-scope-dispose',
name: 'onScopeDispose',
url: 'on-scope-dispose/on-scope-dispose'
},
]
}
] as Page[]
......
const PAGE_PATH = '/pages/composition-api/reactivity/on-scope-dispose/on-scope-dispose'
const PAGE_PATH = '/pages/reactivity/advanced/on-scope-dispose/on-scope-dispose'
describe('onScopeDispose', () => {
let page = null
......@@ -8,16 +8,16 @@ describe('onScopeDispose', () => {
})
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')
const stopScopeBtn = await page.$('#stop-scope-btn')
await stopScopeBtn.tap()
expect(await hasCurrentScope.text()).toBe('hasCurrentScope: false')
expect(await hasCurrentScope.text()).toBe('false')
})
})
\ No newline at end of file
<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>
<button id="stop-scope-btn" class="mt-10" @click="stopScope">stop 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>
<button id="stop-scope-btn" class="mt-10" @click="stopScope">
stop scope
</button>
</view>
</template>
<script setup>
const hasCurrentScope = ref(false)
<script setup lang="uts">
const hasCurrentScope = ref(false)
let scope = null as EffectScope | null
let scope = null as EffectScope | null
const createScope = () => {
scope = effectScope();
(scope as EffectScope).run(() => {
const createScope = () => {
scope = effectScope();
(scope as EffectScope).run(() => {
hasCurrentScope.value = getCurrentScope() != null
onScopeDispose(() => {
hasCurrentScope.value = getCurrentScope() != null
onScopeDispose(() => {
hasCurrentScope.value = getCurrentScope() != null
})
})
}
})
}
const stopScope = () => {
if (scope !== null) {
(scope as EffectScope).stop()
}
const stopScope = () => {
if (scope !== null) {
(scope as EffectScope).stop()
}
</script>
\ No newline at end of file
}
</script>
......@@ -144,7 +144,7 @@ function transform(fileInfo, api) {
- [x] effectScope
- [x] getCurrentScope
- [x] markRaw
- [ ] onScopeDispose
- [x] onScopeDispose
- [ ] shallowReactive
- [ ] shallowReadonly
- [ ] shallowRef
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部