reconcile: support "merge" in objects
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 38/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- typescript
- 领域
- frontend
调研方向
先阅读 reconcile 和 applyState 的实现,然后跟踪 setState 如何应用对象更新。将现有的数组合并行为与提议的第一层对象合并进行比较,并检查 issue 中的示例以确认预期的嵌套行为。当部分对象更新的 API 确定下来、保留当前数组行为,并且覆盖所描述的 store 更新模式时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
A common pattern I believe is to reconcile partial state updates in stores.
For example, part of a store is synced to a backend, so after a push-to-backend operation, it returns an up-to-date data for part of the store values. Other values, like UI related ones are not included in this data.
Passing this raw data into setStore works, but triggers unnecessary updates. It triggers every single key's update, which is an array or object.
Here is my 1st idea to tackle this: running reconcile in a for loop on each 1st level key:
for (const key of Object.keys(data)) {
this.setState(key as any, reconcile(data[key as keyof typeof data]))
}
This works, and when put in a batch() should be performant. Quite a lot of code, so asks for a wrapper function, but should be good.
My 2nd idea is this:
this.setState(reconcile({ ...this.state, ...data }))
This also works. If I understand correctly, it's a tiny bit slower, but the slowness happens in the pure JS code, not in the actual UI updates, so it should still be fast.
When I looked at the source code for reconcile and found that it supports merge, but only for arrays.
I'd like to recommend to add support for merge in objects. To make sure that this does not modify the array behaviours in sub-keys, it should be called something different, "partial" probably.
I believe it'd be as simple as turning off the delete loop in the first level of applyState.
Please tell me if I'm not correct in this. Isn't this a common pattern when using stores?
How do you normally solve this?
- 主要语言
- TypeScript
- 星标
- 36.2k
- 派生
- 1.1k
- 平均合并
- 11 小时 5 分钟
- 30 天内合并 PR
- 475
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
solidjs/solid 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 28/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 12/100
维护者通常 1 天内回复
-
[2.0 / next] <Errored> recovery shows a pending memo's answer to an older input beside the new input未关闭
难度 4/5 3-5 天 新手友好度 20/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 15/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 18/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
oxidecomputer/skepsis#102 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
voidzero-dev/void#677 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
kunchenguid/gh-axi#247 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
lidge-jun/opencodex#8101 · 2 条评论 ·
维护者通常 1 天内回复