A functional write to a store path stores the function instead of applying it (W-6)

Đang mở Phù hợp với người mới
#96 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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
compilers

Hướng nghiên cứu

Bắt đầu trong ref/compile/rt-web.ts tại pathWrite, và phản chiếu mọi thay đổi vào bản sao của nó trong ref/compile/rt.ts. So sánh nó với guessInto ngay bên dưới, thứ đã áp dụng các giá trị hàm; làm cho phép gán đường dẫn cuối cùng áp dụng v khi nó là một hàm. Chạy trình biên dịch trên ref/compile/rt.ts với chương trình ví dụ và kiểm tra rằng các frame nhấp chuột đi qua add1, add2, add3.

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

Mô tả

A functional write to a path of a structured source stores the function instead of applying it. 02 W-6 says x := f writes f applied to the slot, and that "a path target applies f to the path's value", so cart.items := items => [...items, 2] should append. The compiler accepts the program and lowers the write to the runtime's path writer, which assigns f itself to cart.items.

Program

export default component App() {
  source cart := { items: [1] }
  <main>
    <button onClick={() => { cart.items := items => [...items, 2] }}>add</button>
    <p>{len(cart.items)}</p>
  </main>
}

Frames

instant action expected compiled
0 mount add1 add1
1 click add add2 add0
2 click add add3 add0

The expected column is the same program written with Solid's setter, setCart((d) => { d.items = ((items) => [...items, 2])(d.items); }), run on the same clicks. The compiled column is the crate's output on ref/compile/rt.ts.

Cause

pathWrite in ref/compile/rt-web.ts (and its copy in rt.ts) ends with o[keys[keys.length - 1]] = v. guessInto, two lines below it, already handles a function: o[last] = typeof v === "function" ? v(o[last]) : v. Doing the same in pathWrite would match W-6. It is the path writer of a plain structured source (path: pathWrite(setStore)) and of an optimistic store's truth (path: pathWrite(setTruth)).

Versions: main at e650b85. The published @reactivescript/runtime 0.3.1 has the same assignment inline in its store writer, so released apps are affected too.

Ngôn ngữ chính
TypeScript
Star
127
Fork
7
Merge trung bình
15 giờ 42 phút
Pull request đã merge (30 ngày)
63

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/reactivescript

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

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.