提交 4b0db2b9 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(composition api): onScopeDispose

上级 a0363a90
const PAGE_PATH = '/pages/composition-api/reactivity/on-scope-dispose/on-scope-dispose'
describe('onScopeDispose', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
const hasCurrentScope = await page.$('#has-current-scope')
expect(await hasCurrentScope.text()).toBe('hasCurrentScope: false')
const createScopeBtn = await page.$('#create-scope-btn')
await createScopeBtn.tap()
expect(await hasCurrentScope.text()).toBe('hasCurrentScope: true')
const stopScopeBtn = await page.$('#stop-scope-btn')
await stopScopeBtn.tap()
expect(await hasCurrentScope.text()).toBe('hasCurrentScope: false')
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
})
\ No newline at end of file
<template><view class="page">onScopeDispose</view></template>
\ No newline at end of file
<template>
<view class="page">
<text id="has-current-scope">hasCurrentScope: {{ hasCurrentScope }}</text>
<button id="create-scope-btn" class="uni-common-mt" @click="createScope">create scope</button>
<button id="stop-scope-btn" class="uni-common-mt" @click="stopScope">stop scope</button>
</view>
</template>
<script setup>
const hasCurrentScope = ref(false)
let scope = null as EffectScope | null
const createScope = () => {
scope = effectScope();
(scope as EffectScope).run(() => {
hasCurrentScope.value = getCurrentScope() !== null
onScopeDispose(() => {
hasCurrentScope.value = getCurrentScope() !== null
})
})
}
const stopScope = () => {
if (scope !== null) {
(scope as EffectScope).stop()
}
}
</script>
\ No newline at end of file
......@@ -211,7 +211,7 @@
{
name: 'onScopeDispose',
url: 'on-scope-dispose',
enable: false,
enable: true,
},
] as PageItem[],
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册