reconcile: support "merge" in objects
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 38/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu bằng cách đọc các triển khai của reconcile và applyState, sau đó theo dõi cách setState áp dụng các cập nhật đối tượng. So sánh hành vi merge mảng hiện có với merge đối tượng ở cấp đầu tiên được đề xuất và kiểm tra các ví dụ của issue để xác định hành vi lồng nhau mong đợi. Được xem là hoàn tất khi có một API đã được thống nhất cho các cập nhật đối tượng một phần, vẫn giữ nguyên hành vi mảng hiện tại và có coverage cho pattern cập nhật store được mô tả.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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?
- Ngôn ngữ chính
- TypeScript
- Star
- 36.2k
- Fork
- 1.1k
- Merge trung bình
- 11 giờ 5 phút
- Pull request đã merge (30 ngày)
- 475
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của solidjs/solid
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 28/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 12/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[2.0 / next] <Errored> recovery shows a pending memo's answer to an older input beside the new inputĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 18/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của solidjs/solid
Issue tương tự
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
🎙️ task - drop the raw `./node_modules/.bin/rhachet roles boot` line from bhuild's feedback templateĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ehmpathy/rhachet-roles-bhuild#639 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
e2e-failure ready-to-code
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
redhat-developer/rhdh-plugin-export-overlays#4650 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 13 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
omdsh-dev/DSH-better-sidebar#1098 ·
Maintainer thường phản hồi trong vòng 2 ngày