-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(): support batchUpdate context #3064
feat(): support batchUpdate context #3064
Conversation
Passing run #6655 ↗︎Details:
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. |
Codecov Report
@@ Coverage Diff @@
## master #3064 +/- ##
==========================================
+ Coverage 93.21% 93.25% +0.04%
==========================================
Files 296 296
Lines 9696 9757 +61
Branches 1829 1845 +16
==========================================
+ Hits 9038 9099 +61
Misses 412 412
Partials 246 246
|
@@ -724,6 +724,7 @@ export interface BuilderSnippetNode extends BuilderBaseNode { | |||
export interface BuiltinBrickEventHandler { | |||
action: "history.push" | "history.replace" | "history.goBack" | "history.goForward" | "history.reload" | "history.pushQuery" | "history.replaceQuery" | "history.pushAnchor" | "history.block" | "history.unblock" | "segue.push" | "segue.replace" | "alias.push" | "alias.replace" | "localStorage.setItem" | "localStorage.removeItem" | "sessionStorage.setItem" | "sessionStorage.removeItem" | "legacy.go" | "location.reload" | "location.assign" | "window.open" | "event.preventDefault" | "console.log" | "console.error" | "console.warn" | "console.info" | "message.success" | "message.error" | "message.info" | "message.warn" | "handleHttpError" | "context.assign" | "context.replace" | "context.refresh" | "context.load" | "state.update" | "state.refresh" | "state.load" | "tpl.dispatchEvent" | "message.subscribe" | "message.unsubscribe" | "theme.setDarkTheme" | "theme.setLightTheme" | "theme.setTheme" | "mode.setDashboardMode" | "mode.setDefaultMode" | "menu.clearMenuTitleCache" | "menu.clearMenuCache" | "preview.debug" | "analytics.event" | "formstate.update"; | |||
args?: unknown[]; | |||
batch?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前已经支持这种场景,因为在批处理中(值更新过程)不会提交变更事件,需要等变更列表全部更新完之后,才会统一
执行dispatchEvent
(它会自行分析依赖,并触发影响到的值的变更); 并且目前这种操作是同步模式,对过往编排的影响应该不大;
场景:
- name: a
value: 1
- name: b
value: 2
- name: c
value: a + b
- name: d
value: c + 1
普通变更:
- action: state.update
args:
- a
- a + 1
- action: state.update
args:
- b
- b + 1
普通变更 dispatchEvent
的执行顺序是: a -> c -> d -> b -> c -> d
批量变更:
- action: state.update
args:
- name: a
value: a + 1
- name: b
value: b + 1
批量变更 dispatchEvent
的执行顺序是: a -> b -> c -> d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
场景不太一样,
假设 b 依赖 a,c 依赖 a 和 b:
- name: a
- name: b
value: <% STATE.a %>
- name: c
value: <% STATE.a + STATE.b %>
只更新 a:
action: state.update
args:
- a
- ...
这种情况,目前是 a 变更后,c 应该会触发两次更新:
b -- c
/
a
\
c
具体 @willc001 看看是不是这样的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b -- c
/
a
\
c
实际如果只更新 a 并不会有这种场景的出现,因为批处理阻止了 context 值变更后的 dispatchEvent
事件;在变更过程中,我们会将变更列表收集起来,称之为 updateContexts
, 然后根据 updateContexts
计算出其依赖链称之为 affectContexts
, 然后等待值更新后,才触发事件变更;
这里 updateContexts = { a }; affectContexts = { b, c }
所以正确的执行顺序应该是: a -> b - c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注意这里不是走 state.update 数组,而是之前的更新单个 state 的语法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果是之前的写法那 c 就会变更 2 次了,这种是符合之前的预期的
baabbf2
to
5d51c33
Compare
0a27724
to
fffc09b
Compare
依赖检查
组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。
请勾选以下两组选项其中之一:
或者:
提交信息检查
Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。
破坏性变更:
feat
作为提交类型。BREAKING CHANGE: 你的变更说明
。新特性:
feat
作为提交类型。问题修复:
fix
作为提交类型。杂项工作:
即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:
chore
,docs
,test
等作为提交类型。