Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
e3a4ded2
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
361
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看板
提交
e3a4ded2
编写于
8个月前
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(reactivity): effectScope
上级
ebb2eb00
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
67 addition
and
34 deletion
+67
-34
pages/index/index.uvue
pages/index/index.uvue
+5
-0
pages/reactivity/advanced/effect-scope/effect-scope.test.js
pages/reactivity/advanced/effect-scope/effect-scope.test.js
+22
-13
pages/reactivity/advanced/effect-scope/effect-scope.uvue
pages/reactivity/advanced/effect-scope/effect-scope.uvue
+39
-20
refactor_options-API-composition-API-correspondence.md
refactor_options-API-composition-API-correspondence.md
+1
-1
未找到文件。
pages/index/index.uvue
浏览文件 @
e3a4ded2
...
...
@@ -581,6 +581,11 @@ export default {
name: 'customRef',
url: 'custom-ref/custom-ref'
},
{
id: 'effect-scope',
name: 'effectScope',
url: 'effect-scope/effect-scope'
},
]
}
] as Page[]
...
...
This diff is collapsed.
Click to expand it.
pages/reactivity/advanced/effect-scope/effect-scope.test.js
浏览文件 @
e3a4ded2
const
PAGE_PATH
=
'
/pages/
composition-api/reactivity
/effect-scope/effect-scope
'
const
PAGE_PATH
=
'
/pages/
reactivity/advanced
/effect-scope/effect-scope
'
describe
(
'
effectScope
'
,
()
=>
{
const
isWeb
=
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)
let
page
=
null
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
(
'
basic
'
,
async
()
=>
{
const
counter
=
await
page
.
$
(
'
#counter
'
)
expect
(
await
counter
.
text
()).
toBe
(
'
counter:
0
'
)
expect
(
await
counter
.
text
()).
toBe
(
'
0
'
)
const
watchCounterRes
=
await
page
.
$
(
'
#watch-counter-res
'
)
expect
(
await
watchCounterRes
.
text
()).
toBe
(
isWeb
?
'
watch counter result:
'
:
'
watch counter result:
'
)
const
watchCounterRes
=
await
page
.
$
(
'
#watch-counter-res
'
)
if
(
isAndroid
||
isWeb
){
expect
(
await
watchCounterRes
.
text
()).
toBe
(
''
)
}
if
(
isIos
){
expect
(
await
watchCounterRes
.
text
()).
toBe
(
null
)
}
const
watchEffectCounterRes
=
await
page
.
$
(
'
#watch-effect-counter-res
'
)
expect
(
await
watchEffectCounterRes
.
text
()).
toBe
(
'
watchEffect counter result:
counter: 0
'
)
expect
(
await
watchEffectCounterRes
.
text
()).
toBe
(
'
counter: 0
'
)
const
incrementCounterBtn
=
await
page
.
$
(
'
#increment-counter-btn
'
)
await
incrementCounterBtn
.
tap
()
expect
(
await
counter
.
text
()).
toBe
(
'
counter:
1
'
)
expect
(
await
watchCounterRes
.
text
()).
toBe
(
'
watch counter result:
newVal: 1, oldVal: 0
'
)
expect
(
await
watchEffectCounterRes
.
text
()).
toBe
(
'
watchEffect counter result:
counter: 1
'
)
expect
(
await
counter
.
text
()).
toBe
(
'
1
'
)
expect
(
await
watchCounterRes
.
text
()).
toBe
(
'
newVal: 1, oldVal: 0
'
)
expect
(
await
watchEffectCounterRes
.
text
()).
toBe
(
'
counter: 1
'
)
const
stopEffectScopeBtn
=
await
page
.
$
(
'
#stop-effect-scope-btn
'
)
await
stopEffectScopeBtn
.
tap
()
await
incrementCounterBtn
.
tap
()
expect
(
await
counter
.
text
()).
toBe
(
'
counter:
2
'
)
expect
(
await
watchCounterRes
.
text
()).
toBe
(
'
watch counter result:
newVal: 1, oldVal: 0
'
)
expect
(
await
watchEffectCounterRes
.
text
()).
toBe
(
'
watchEffect counter result:
counter: 1
'
)
expect
(
await
counter
.
text
()).
toBe
(
'
2
'
)
expect
(
await
watchCounterRes
.
text
()).
toBe
(
'
newVal: 1, oldVal: 0
'
)
expect
(
await
watchEffectCounterRes
.
text
()).
toBe
(
'
counter: 1
'
)
})
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pages/reactivity/advanced/effect-scope/effect-scope.uvue
浏览文件 @
e3a4ded2
<template>
<view class="page">
<text id="counter">counter: {{ counter }}</text>
<text id="watch-counter-res" class="mt-10">watch counter result: {{ watchCounterRes }}</text>
<text id="watch-effect-counter-res" class="mt-10">watchEffect counter result:
{{ watchEffectCounterRes }}</text>
<button id="increment-counter-btn" class="mt-10" @click="() => {counter++}">increment counter</button>
<button id="stop-effect-scope-btn" class="mt-10" @click="stopEffectScope">stop effect scope</button>
<view class="flex justify-between flex-row mb-10">
<text>counter:</text>
<text id="counter">{{ counter }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>watch counter result:</text>
<text id="watch-counter-res">{{ watchCounterRes }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>watchEffect counter result:</text>
<text id="watch-effect-counter-res">{{ watchEffectCounterRes }}</text>
</view>
<button
id="increment-counter-btn"
class="mt-10"
@click="
() => {
counter++;
}
">
increment counter
</button>
<button id="stop-effect-scope-btn" class="mt-10" @click="stopEffectScope">
stop effect scope
</button>
</view>
</template>
<script setup>
const scope = effectScope()
<script setup
lang="uts"
>
const scope = effectScope()
const counter = ref(0)
const counter = ref(0)
const watchCounterRes = ref('')
const watchCounterRes = ref('')
const watchEffectCounterRes = ref('')
const watchEffectCounterRes = ref('')
scope.run(() => {
watch(counter, (newVal : number, oldVal : number) => {
watchCounterRes.value = `newVal: ${newVal}, oldVal: ${oldVal}`
})
scope.run(() => {
watch(counter, (newVal : number, oldVal : number) => {
watchCounterRes.value = `newVal: ${newVal}, oldVal: ${oldVal}`
})
watchEffect(() => {
watchEffectCounterRes.value = `counter: ${counter.value}`
})
watchEffect(() => {
watchEffectCounterRes.value = `counter: ${counter.value}`
})
})
const stopEffectScope = () => scope.stop()
</script>
\ No newline at end of file
const stopEffectScope = () => scope.stop()
</script>
This diff is collapsed.
Click to expand it.
refactor_options-API-composition-API-correspondence.md
浏览文件 @
e3a4ded2
...
...
@@ -141,7 +141,7 @@ function transform(fileInfo, api) {
-
[x] unRef
-
[x] customRef
-
[
] effectScope
-
[
x
] effectScope
-
[ ] getCurrentScope
-
[ ] markRaw
-
[ ] onScopeDispose
...
...
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
新手
引导
客服
返回
顶部