Add DEV.setSignal so devtools can write a signal or store node

Đã đóng
#4,679 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
devtools

Hướng nghiên cứu

Start from the DEV object that already exposes getSignals, getSources and getObservers, and from the write path behind the setter createSignal returns. Store slot nodes (those with _host and _key) must go through the store setter so onStoreNodeUpdate and subscribers fire. Done means DEV.setSignal works in dev builds for both node kinds, honours equals and scheduling, and can be called from outside an owned scope.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Devtools can read a signal through DEV, but cannot write one. I'd like a dev-only hook that sets a signal node, or the slot node of a store property, to a new value and notifies its subscribers.

DEV.setSignal(node: Signal<any>, value: unknown): void

Why

The state editor in solidjs/solid-start-devtools#41 lets a developer change a signal or store value from the devtools panel and see the app update. The panel gets nodes from DEV.getSignals and DEV.getSources. It does not have the setter the app got from createSignal or createStore, and writing node._value changes the value without notifying anyone.

To get around this, the PR creates its own createSignal(0) and redefines about 20 fields on that node (_value, _subs, _subsTail, _pendingValue, _statusFlags, _equals, _time, _notifiedAt, _owner, _transition, _firewall and others) as getters and setters that forward to the target node. It then calls its own setter, so the runtime's write path runs against the target. For a store slot it also writes _host.v[_key] and _host.pb[_key] directly.

This works on 2.0.0-rc.20, but it depends on private field names. A rename or a new field in a release breaks editing without a type error. The DEV object already has getSignals, getSources and getObservers, so the runtime is the place that can keep a write hook working.

Proposed behavior

  • For a signal node: same as calling the setter createSignal returned, including equals, notification and scheduling.
  • For a store property slot node (a node with _host and _key): same as writing that property through the store setter, so onStoreNodeUpdate and the store's subscribers see it.
  • Only in dev builds, like the rest of DEV.
  • Callable outside an owned scope, from a devtools UI event. The devtools call it inside runWithOwner(null, …) today to avoid REACTIVE_WRITE_IN_OWNED_SCOPE.

Nested paths are not needed. The devtools build the new value for the node from a path itself, and only write plain objects and arrays.

Devtools side

solidjs/solid-start-devtools#41 already calls DEV.setSignal when it is a function and falls back to the bridge otherwise, so the bridge can be removed once a release has the hook.

Ngôn ngữ chính
TypeScript
Star
36.2k
Fork
1.1k
Merge trung bình
9 giờ 58 phút
Pull request đã merge (30 ngày)
474

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của solidjs/solid

Tất cả issue của solidjs/solid

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.