applyPatches produces same result, but should it also preserve identity?

オープン
#909 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
javascript
領域
frontend

調査の方向性

リンクされているCodeSandboxの再現から始め、unshiftの例についてproduceとapplyPatchesのアイデンティティの挙動を比較します。itemsに対して生成されるreplaceおよびadd操作を確認し、オブジェクトのアイデンティティを保持することと、移動されたインデックスに関する十分な情報を提供することが意図された要件かどうかを明らかにします。文書化された決定、または合意された実装範囲が確定すれば完了です。

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

説明

question

🙋‍♂ Question

Consider the following code:

https://codesandbox.io/s/immer-sandbox-forked-t7ghd9?file=/src/index.ts

While patchedState is indeed deep equal to producedState, there is a difference in that produce preserves object identity, but applyPatches does not.

Is this a property that would be useful? I arrived at this during a different route, which may be my real question: when an unshift happens, instead of an add op for path ["items", 0], which I expected, instead the patches include a replace op for the first two items in the array, and then an add op for position ["items", 2]. Applying these patches will result in object identity being broken.

I am experimenting with using Immer for change tracking, and this makes life more complicated: I want to track whether I need to update paths if their indices have shifted, but I don't get sufficient information from the patch to determine that.

Link to repro

https://codesandbox.io/s/immer-sandbox-forked-t7ghd9?file=/src/index.ts

Environment

We only accept questions against the latest Immer version.

  • Immer version: 9.0.12
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
主要言語
JavaScript
スター
29k
フォーク
905
平均マージ
3日 16時間
マージ済み PR(30日)
22

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

immerjs/immer のほかの issue

immerjs/immer の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

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

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