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

refactor(reactivity): triggerRef

...@@ -622,6 +622,11 @@ export default { ...@@ -622,6 +622,11 @@ export default {
name: 'toRaw', name: 'toRaw',
url: 'to-raw/to-raw' url: 'to-raw/to-raw'
}, },
{
id: 'trigger-ref',
name: 'triggerRef',
url: 'trigger-ref/trigger-ref'
},
] ]
} }
] as Page[] ] as Page[]
......
const PAGE_PATH = '/pages/composition-api/reactivity/trigger-ref/trigger-ref' const PAGE_PATH = '/pages/reactivity/advanced/trigger-ref/trigger-ref'
describe('triggerRef', () => { describe('triggerRef', () => {
let page = null let page = null
...@@ -8,16 +8,16 @@ describe('triggerRef', () => { ...@@ -8,16 +8,16 @@ describe('triggerRef', () => {
}) })
it('basic', async () => { it('basic', async () => {
const stateCount = await page.$('#state-count') const stateCount = await page.$('#state-count')
expect(await stateCount.text()).toBe('state.count: 0') expect(await stateCount.text()).toBe('0')
const incrementStateCountBtn = await page.$('#increment-state-count-btn') const incrementStateCountBtn = await page.$('#increment-state-count-btn')
await incrementStateCountBtn.tap() await incrementStateCountBtn.tap()
expect(await stateCount.text()).toBe('state.count: 0') expect(await stateCount.text()).toBe('0')
const triggerRefStateBtn = await page.$('#trigger-ref-state-btn') const triggerRefStateBtn = await page.$('#trigger-ref-state-btn')
await triggerRefStateBtn.tap() await triggerRefStateBtn.tap()
expect(await stateCount.text()).toBe('state.count: 1') expect(await stateCount.text()).toBe('1')
}) })
}) })
\ No newline at end of file
<template> <template>
<view class="page"> <view class="page">
<text id="state-count" class="mb-10">state.count: {{ state.count }}</text> <view class="flex justify-between flex-row mb-10">
<button id="increment-state-count-btn" class="mb-10" @click="incrementStateCount">increment <text>state.count:</text>
state.count</button> <text id="state-count">{{ state.count }}</text>
<button id="trigger-ref-state-btn" @click="triggerRefState">trigger state</button> </view>
<button
id="increment-state-count-btn"
class="mb-10"
@click="incrementStateCount">
increment state.count
</button>
<button id="trigger-ref-state-btn" @click="triggerRefState">
trigger state
</button>
</view> </view>
</template> </template>
<script setup> <script setup lang="uts">
type State = { type State = {
count: number count: number
} }
const state = shallowRef({ const state = shallowRef({
count: 0 count: 0
} as State) } as State)
const incrementStateCount = () => { const incrementStateCount = () => {
state.value.count++ state.value.count++
} }
const triggerRefState = () => { const triggerRefState = () => {
triggerRef(state) triggerRef(state)
} }
</script> </script>
\ No newline at end of file
...@@ -149,7 +149,7 @@ function transform(fileInfo, api) { ...@@ -149,7 +149,7 @@ function transform(fileInfo, api) {
- [x] shallowReadonly - [x] shallowReadonly
- [x] shallowRef - [x] shallowRef
- [x] toRaw - [x] toRaw
- [ ] triggerRef - [x] triggerRef
## directives ## directives
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部