提交 027548a7 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(composition api): shallowReadonly

上级 59a837a9
const PAGE_PATH = '/pages/composition-api/reactivity/shallow-readonly/shallow-readonly'
describe('shallowReadonly', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
let stateCount = await page.$('#state-count')
expect(await stateCount.text()).toBe('state.count: 0')
let stateNestedCount = await page.$('#state-nested-count')
expect(await stateNestedCount.text()).toBe('state.nested.count: 0')
const incrementStateCountBtn = await page.$('#increment-state-count-btn')
await incrementStateCountBtn.tap()
const incrementStateNestedCountBtn = await page.$('#increment-state-nested-count-btn')
await incrementStateNestedCountBtn.tap()
expect(await stateCount.text()).toBe('state.count: 0')
expect(await stateNestedCount.text()).toBe('state.nested.count: 0')
const updatePageRenderBtn = await page.$('#update-page-render-btn')
await updatePageRenderBtn.tap()
stateCount = await page.$('#state-count')
expect(await stateCount.text()).toBe('state.count: 0')
stateNestedCount = await page.$('#state-nested-count')
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">shallowReadonly</view></template>
\ No newline at end of file
<template>
<view :key="pageKey" 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" class="uni-common-mb" @click="incrementStateNestedCount">
increment state.nested.count
</button>
<button id="update-page-render-btn" @click="updatePageRender">update page render</button>
</view>
</template>
<script setup>
let pageKey = ref<number>(0)
type StateNested = {
count : number
}
type State = {
count : number,
nested : StateNested
}
const state = shallowReadonly({
count: 0,
nested: {
count: 0
} as StateNested
} as State)
const incrementStateCount = () => {
state.count++
}
const incrementStateNestedCount = () => {
state.nested.count++
}
const updatePageRender = () => {
pageKey.value = Date.now()
}
</script>
\ No newline at end of file
......@@ -186,7 +186,7 @@
{
name: 'shallowReadonly',
url: 'shallow-readonly',
enable: false,
enable: true,
},
{
name: 'toRaw',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册