Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
9e44579e
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
360
Star
3
Fork
8
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello-uvue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9e44579e
编写于
8个月前
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(reactivity): watchSyncEffect
上级
c93a4067
master
alpha
dev
feature/props-emit-type
master-old
refactor_options-API-composition-API-correspondence
v_4.45
v_4.45-alpha
v_4.44
v_4.43-alpha
v_4.42-alpha
v_4.41-alpha
v_4.36
v_4.36-alpha
v_4.35-alpha
v_4.34-alpha
v_4.33-alpha
v_4.32-alpha
v_4.31-alpha
v_4.29
v_4.28
v_4.28-alpha
v_4.27-alpha
v_4.26-alpha
v_4.25-alpha
无相关合并请求
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
140 addition
and
94 deletion
+140
-94
pages/index/index.uvue
pages/index/index.uvue
+5
-2
pages/reactivity/core/watch-sync-effect/watch-sync-effect.test.js
...activity/core/watch-sync-effect/watch-sync-effect.test.js
+66
-61
pages/reactivity/core/watch-sync-effect/watch-sync-effect.uvue
.../reactivity/core/watch-sync-effect/watch-sync-effect.uvue
+62
-24
refactor_options-API-composition-API-correspondence.md
refactor_options-API-composition-API-correspondence.md
+7
-7
未找到文件。
pages/index/index.uvue
浏览文件 @
9e44579e
...
...
@@ -517,6 +517,11 @@ export default {
name: 'watchPostEffect',
url: 'watch-post-effect/watch-post-effect'
},
{
id: 'watch-sync-effect',
name: 'watchSyncEffect',
url: 'watch-sync-effect/watch-sync-effect'
},
]
}
] as Page[]
...
...
@@ -717,8 +722,6 @@ export default {
})
return
}
console.log('parentUrl', parentUrl)
console.log('page', page)
uni.navigateTo({
url: `/pages/${parentUrl}/${page.url}`
})
...
...
This diff is collapsed.
Click to expand it.
pages/reactivity/core/watch-sync-effect/watch-sync-effect.test.js
浏览文件 @
9e44579e
const
PAGE_PATH
=
'
/pages/
composition-api/reactivity
/watch-sync-effect/watch-sync-effect
'
const
PAGE_PATH
=
'
/pages/
reactivity/core
/watch-sync-effect/watch-sync-effect
'
describe
(
'
watchSyncEffect
'
,
()
=>
{
let
page
=
null
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
()
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isIos
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
count
'
,
async
()
=>
{
const
count
=
await
page
.
$
(
'
#count
'
)
expect
(
await
count
.
text
()).
toBe
(
'
count:
0
'
)
expect
(
await
count
.
text
()).
toBe
(
'
0
'
)
// watch
const
watchCountRes
=
await
page
.
$
(
'
#watch-count-res
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 0, count ref text: coun
t: 0
'
)
'
count: 0, count ref tex
t: 0
'
)
// track
const
watchCountTrackNum
=
await
page
.
$
(
'
#watch-count-track-num
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
ios
'
)
)
{
if
(
isAndroid
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
3
'
)
}
else
if
(
isIos
)
{
// TODO: 确认 IOS 的差异是否正常
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
11
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
11
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
6
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
6
'
)
}
const
watchCountCleanupRes
=
await
page
.
$
(
'
#watch-count-cleanup-res
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup
result: watch count cleanup
: 0
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup: 0
'
)
// watch count and obj.num
const
watchCountAndObjNumRes
=
await
page
.
$
(
'
#watch-count-obj-num-res
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result:
count: 0, obj.num: 0
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
count: 0, obj.num: 0
'
)
const
incrementBtn
=
await
page
.
$
(
'
#
increment-btn
'
)
const
incrementBtn
=
await
page
.
$
(
'
.
increment-btn
'
)
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count:
1
'
)
expect
(
await
count
.
text
()).
toBe
(
'
1
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 1, count ref text: coun
t: 0
'
)
'
count: 1, count ref tex
t: 0
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
ios
'
)
)
{
if
(
isAndroid
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
3
'
)
}
else
if
(
isIos
)
{
// TODO: 确认 IOS 的差异是否正常
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
19
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
19
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
9
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
9
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup
result: watch count cleanup
: 1
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup: 1
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result:
count: 1, obj.num: 0
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
count: 1, obj.num: 0
'
)
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count:
2
'
)
expect
(
await
count
.
text
()).
toBe
(
'
2
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text: coun
t: 1
'
)
'
count: 2, count ref tex
t: 1
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
ios
'
)
)
{
if
(
isAndroid
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
3
'
)
}
else
if
(
isIos
)
{
// TODO: 确认 IOS 的差异是否正常
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
27
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
27
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
12
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
12
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup
result: watch count cleanup
: 2
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result:
count: 2, obj.num: 0
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
count: 2, obj.num: 0
'
)
// stop watch
const
stopWatchCountBtn
=
await
page
.
$
(
'
#
stop-watch-count-btn
'
)
const
stopWatchCountBtn
=
await
page
.
$
(
'
.
stop-watch-count-btn
'
)
await
stopWatchCountBtn
.
tap
()
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count:
3
'
)
expect
(
await
count
.
text
()).
toBe
(
'
3
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text: coun
t: 1
'
)
'
count: 2, count ref tex
t: 1
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
ios
'
)
)
{
if
(
isAndroid
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
3
'
)
}
else
if
(
isIos
)
{
// TODO: 确认 IOS 的差异是否正常
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
27
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
27
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number:
12
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
12
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup
result: watch count cleanup
: 2
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result:
count: 3, obj.num: 0
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
count: 3, obj.num: 0
'
)
})
it
(
'
obj
'
,
async
()
=>
{
const
objStr
=
await
page
.
$
(
'
#obj-str
'
)
expect
(
await
objStr
.
text
()).
toBe
(
'
obj.str:
num: 0
'
)
expect
(
await
objStr
.
text
()).
toBe
(
'
num: 0
'
)
const
objNum
=
await
page
.
$
(
'
#obj-num
'
)
expect
(
await
objNum
.
text
()).
toBe
(
'
obj.num:
0
'
)
expect
(
await
objNum
.
text
()).
toBe
(
'
0
'
)
const
objBool
=
await
page
.
$
(
'
#obj-bool
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
obj.bool:
false
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
false
'
)
const
objArr
=
await
page
.
$
(
'
#obj-arr
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
obj.arr:
[0]
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
[0]
'
)
const
watchObjRes
=
await
page
.
$
(
'
#watch-obj-res
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)
||
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
ios
'
)
)
{
if
(
isWeb
||
isIos
)
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result:
obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}
'
'
obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}
'
)
}
else
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result:
obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}
'
'
obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}
'
)
}
const
watchObjStrRes
=
await
page
.
$
(
'
#watch-obj-str-res
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 0, obj.str ref text: obj.str
: num: 0
'
)
'
str: num: 0, obj.str ref text
: num: 0
'
)
// trigger
const
watchObjStrTriggerNum
=
await
page
.
$
(
'
#watch-obj-str-trigger-num
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
watch obj.str trigger number:
1
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
1
'
)
const
watchObjArrRes
=
await
page
.
$
(
'
#watch-obj-arr-res
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result:
arr: [0]
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
arr: [0]
'
)
const
updateObjBtn
=
await
page
.
$
(
'
#
update-obj-btn
'
)
const
updateObjBtn
=
await
page
.
$
(
'
.
update-obj-btn
'
)
await
updateObjBtn
.
tap
()
expect
(
await
objStr
.
text
()).
toBe
(
'
obj.str:
num: 1
'
)
expect
(
await
objNum
.
text
()).
toBe
(
'
obj.num:
1
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
obj.bool:
true
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
obj.arr:
[0,1]
'
)
expect
(
await
objStr
.
text
()).
toBe
(
'
num: 1
'
)
expect
(
await
objNum
.
text
()).
toBe
(
'
1
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
true
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
[0,1]
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)
||
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
ios
'
)
)
{
if
(
isWeb
||
isIos
)
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result:
obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
'
obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
)
}
else
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result:
obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}
'
'
obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}
'
)
}
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, obj.str ref text: obj.str
: num: 0
'
)
'
str: num: 1, obj.str ref text
: num: 0
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
watch obj.str trigger number:
2
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
2
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result:
arr: [0,1]
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
arr: [0,1]
'
)
const
watchCountAndObjNumRes
=
await
page
.
$
(
'
#watch-count-obj-num-res
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result:
count: 3, obj.num: 1
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
count: 3, obj.num: 1
'
)
})
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pages/reactivity/core/watch-sync-effect/watch-sync-effect.uvue
浏览文件 @
9e44579e
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1; padding-bottom: 20px">
<!-- #endif -->
<!-- #endif -->
<view class="page">
<text id="count" ref="countRef" class="mb-10">count: {{ count }}</text>
<text id="watch-count-res" class="mb-10">watch count result: {{ watchCountRes }}</text>
<text id="watch-count-track-num" class="mb-10">watch count track number: {{ watchCountTrackNum }}</text>
<text id="watch-count-cleanup-res" class="mb-10">watch count cleanup result:
{{ watchCountCleanupRes }}</text>
<button id="increment-btn" class="mb-10" @click="increment">
increment
</button>
<button id="stop-watch-count-btn" class="mb-10" @click="triggerStopWatchCount">
<view class="flex justify-between flex-row mb-10">
<text>count:</text>
<text id="count" ref="countRef">{{ count }}</text>
</view>
<view class="flex justify-between mb-10">
<text>watch count result:</text>
<text id="watch-count-res">{{ watchCountRes }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>watch count track number:</text>
<text id="watch-count-track-num">{{ watchCountTrackNum }}</text>
</view>
<view class="flex justify-between mb-10">
<text>watch count cleanup number:</text>
<text id="watch-count-cleanup-res">{{ watchCountCleanupRes }}</text>
</view>
<button class="increment-btn mb-10" @click="increment">increment</button>
<button class="stop-watch-count-btn mb-10" @click="triggerStopWatchCount">
stop watch count
</button>
<text id="obj-str" ref="objStrRef" class="mb-10">obj.str: {{ obj.str }}</text>
<text id="watch-obj-str-trigger-num" class="mb-10">watch obj.str trigger number:
{{ watchObjStrTriggerNum }}</text>
<text id="obj-num" class="mb-10">obj.num: {{ obj.num }}</text>
<text id="obj-bool" ref="objBoolRef" class="mb-10">obj.bool: {{ obj.bool }}</text>
<text id="obj-arr" ref="objArrRef" class="mb-10">obj.arr: {{ JSON.stringify(obj.arr) }}</text>
<text id="watch-obj-res" class="mb-10">watch obj result: {{ watchObjRes }}</text>
<text id="watch-obj-str-res" class="mb-10">watch obj.str result: {{ watchObjStrRes }}</text>
<text id="watch-obj-arr-res" class="mb-10">watch obj.arr result: {{ watchObjArrRes }}</text>
<button id="update-obj-btn" class="mb-10" @click="updateObj">
<view class="flex justify-between flex-row mb-10">
<text>obj.str:</text>
<text id="obj-str" ref="objStrRef">{{ obj.str }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>watch obj.str trigger number:</text>
<text id="watch-obj-str-trigger-num">{{ watchObjStrTriggerNum }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>obj.num:</text>
<text id="obj-num">{{ obj.num }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>obj.bool:</text>
<text id="obj-bool" ref="objBoolRef">{{ obj.bool }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>obj.arr:</text>
<text id="obj-arr" ref="objArrRef">{{ JSON.stringify(obj.arr) }}</text>
</view>
<view class="flex justify-between mb-10">
<text>watch obj result:</text>
<text id="watch-obj-res">{{ watchObjRes }}</text>
</view>
<view class="flex justify-between mb-10">
<text>watch obj.str result:</text>
<text id="watch-obj-str-res">{{ watchObjStrRes }}</text>
</view>
<view class="flex justify-between mb-10">
<text>watch obj.arr result:</text>
<text id="watch-obj-arr-res">{{ watchObjArrRes }}</text>
</view>
<button class="update-obj-btn mb-10" @click="updateObj">
update obj
</button>
<text id="watch-count-obj-num-res" class="mb-10">watch count and obj.num result:
{{ watchCountAndObjNumRes }}</text>
<view class="flex justify-between mb-10">
<text>watch count and obj.num result:</text>
<text id="watch-count-obj-num-res">{{ watchCountAndObjNumRes }}</text>
</view>
</view>
<!-- #ifdef APP -->
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup>
<script setup
lang='uts'
>
type Obj = {
num : number,
str : string,
...
...
This diff is collapsed.
Click to expand it.
refactor_options-API-composition-API-correspondence.md
浏览文件 @
9e44579e
...
...
@@ -122,13 +122,13 @@ function transform(fileInfo, api) {
-
[x] circular reference
## reactivity
-
[
] ref
-
[
] reactive
-
[
] computed computed
-
[
] watch watch
-
[
] watchEffect
-
[
] watchPostEffect
-
[
] watchSyncEffect
-
[
x
] ref
-
[
x
] reactive
-
[
x
] computed computed
-
[
x
] watch watch
-
[
x
] watchEffect
-
[
x
] watchPostEffect
-
[
x
] watchSyncEffect
-
[ ] readonly
-
[ ] customRef
-
[ ] effectScope
...
...
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
反馈
建议
客服
返回
顶部