Idea: forbid grabbing non draftables in strict mode

未關閉
#686 1 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 4 天內回覆

@Gelio 已經在處理了。

開始於 2020年12月3日。

  • #715 來自 @Gelio —— 未關閉

評估

難度
5/5
預估耗時
一週以上
新手友好度
25/100
Issue 類型
功能
描述清晰度
需要釐清
活躍度
停滯
技術堆疊
javascript

研究方向

先檢視所參照的 issue #674,以及 Immer 目前對無法轉換為 draft 的類別實例的行為。此提案尚未決定要在 mutableRef、unsafe、original 和 enableStrictMode 之間選擇哪一個作為 API;要完成這項工作,需要確定設計,並實作 strict mode 與向後相容性所對應的行為。

由索引模型根據 Issue 內容生成。

描述

breaking change proposal

🚀 Feature Proposal

See #674 and many other issues where people are surprised that Immer by default totally ignores their class instances.
The idea is that if a field contains a non-draftable object, it becomes unreadable. E.g.: produce(state, draft => { draft.buffer; }) would throw. To still use the buffer inside a draft, a explicit signal needs to be given, e.g. produce(state, draft => { mutableRef(draft.buffer).push(17); ).

Not sure about the name: mutableRef, unsafe could all work. Or maybe we could even reuse the existing original method for this purpose, although that might be confusing.

For easy backward compatibility an option enableStrictMode(boolean) could be used, by default off in the current version, and enabled in the next major.

Can this be solved in user-land code?

No

主要語言
JavaScript
星號
29k
分支
905
平均合併
3 天 16 小時
30 天內合併 PR
22

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

immerjs/immer 的其他 Issue

查看 immerjs/immer 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。