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

Offen Anfängerfreundlich
#96 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
84/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
typescript
Bereich
compilers

Rechercherichtung

Beginne in ref/compile/rt-web.ts bei pathWrite, und spiegle jede Änderung in seiner Kopie in ref/compile/rt.ts wider. Vergleiche es mit guessInto direkt darunter, das bereits Funktionswerte anwendet; sorge dafür, dass die abschließende Pfadzuweisung v anwendet, wenn es eine Funktion ist. Führe den Compiler auf ref/compile/rt.ts mit dem Beispielprogramm aus und prüfe, dass die Click-Frames add1, add2, add3 durchlaufen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
TypeScript
Sterne
127
Forks
7
Ø Merge
15 Std. 42 Min.
Gemergte PRs (30 T.)
63

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus solidjs/reactivescript

Alle Issues in solidjs/reactivescript

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.