提交 59a837a9 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(composition api): shallowReactive

上级 9fc43c68
const PAGE_PATH = '/pages/composition-api/reactivity/shallow-reactive/shallow-reactive'
describe('shallowReactive', () => {
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 stateCount = await page.$('#state-count')
expect(await stateCount.text()).toBe('state.count: 0')
const stateNestedCount = await page.$('#state-nested-count')
expect(await stateNestedCount.text()).toBe('state.nested.count: 0')
const incrementStateNestedCountBtn = await page.$('#increment-state-nested-count-btn')
await incrementStateNestedCountBtn.tap()
expect(await stateNestedCount.text()).toBe('state.nested.count: 0')
const incrementStateCountBtn = await page.$('#increment-state-count-btn')
await incrementStateCountBtn.tap()
expect(await stateCount.text()).toBe('state.count: 1')
expect(await stateNestedCount.text()).toBe('state.nested.count: 1')
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
})
\ No newline at end of file
<template><view class="page">shallowReactive</view></template>
\ No newline at end of file
<template>
<view class="page">
<text id="state-count" class="uni-common-mb">state.count: {{ state.count }}</text>
<text id="state-nested-count" class="uni-common-mb">state.nested.count: {{ state.nested.count }}</text>
<button id="increment-state-count-btn" class="uni-common-mb" @click="incrementStateCount">
increment state.count
</button>
<button id="increment-state-nested-count-btn" @click="incrementStateNestedCount">
increment state.nested.count
</button>
</view>
</template>
<script setup>
type StateNested = {
count : number
}
type State = {
count : number,
nested : StateNested
}
const state = shallowReactive({
count: 0,
nested: {
count: 0
} as StateNested
} as State)
const incrementStateCount = () => {
state.count++
}
const incrementStateNestedCount = () => {
state.nested.count++
}
</script>
\ No newline at end of file
......@@ -181,7 +181,7 @@
{
name: 'shallowReactive',
url: 'shallow-reactive',
enable: false,
enable: true,
},
{
name: 'shallowReadonly',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册