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

未关闭 适合新手
#96 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
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 分钟
30 天内合并 PR
63

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

solidjs/reactivescript 的其他 Issue

查看 solidjs/reactivescript 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。