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

オープン 初心者向け
#96 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
compilers

調査の方向性

ref/compile/rt-web.ts の pathWrite から始め、変更は ref/compile/rt.ts 内のコピーにも同様に反映してください。すぐ下の guessInto と比較してください。これはすでに関数値を適用しています。最後のパス代入で、それが関数である場合に v を適用するようにしてください。例のプログラムで ref/compile/rt.ts に対してコンパイラを実行し、クリックフレームが add1、add2、add3 と進むことを確認してください。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
127
フォーク
7
平均マージ
15時間 42分
マージ済み PR(30日)
63

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

solidjs/reactivescript のほかの issue

solidjs/reactivescript の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。