[Feature Request] Support for "Splice" patches in arrays for CRDT/Y.js integration (and others)
メンテナーはふだん 4 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- javascript
調査の方向性
まず、splice、shift、unshift に対する Immer の現在の配列パッチ生成を、提案されている arraySplice オプションおよびパッチ形式と照らし合わせて評価します。Y.js、Automerge、MobX のユースケースと設計を比較します。デフォルトの JSON Patch の動作を維持し、列挙された配列操作をカバーする、合意済みの opt-in の splice 表現が定まれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Currently, when performing array operations like splice(), shift(), or unshift(), Immer generates standard JSON patches (RFC 6902). While spec-compliant, this approach is inefficient for arrays when items are added or removed from the middle.
For example, given [1, 2, 3, 4], calling .splice(1, 1) results in:
- replace index 1 with 3
- replace index 2 with 4
- remove index 3
The Problem
This "shifting" behavior is problematic for CRDTs (like Y.js) or observation-based libraries (like MobX).
Performance: Large arrays trigger a cascade of patches for a single deletion.
Convergence: In Y.js, "replacing" an element is different from "shifting" it. If Immer reports that every element after the splice point has been replaced, the CRDT loses the identity of those objects, breaking the ability to merge concurrent changes effectively.
Proposed Solution
I propose an optional configuration (e.g., arraySplice: true) that generates a non-standard splice operation for array mutations. This would group push, pop, shift, unshift, and splice into a single descriptive patch.
Example Proposed Patch Format:
{
"op": "splice",
"path": "/arr",
"index": 1,
"deleteCount": 1,
"items": [...]
}
Use Case
Y.js / Automerge integration: Directly mapping a splice patch to yArray.delete(index, count) and yArray.insert(index, items).
In MobX / other libs it is just calling a splice operation instead.
Performance Optimization: Reducing the payload size when syncing state across WebSockets.
Identity Preservation: Ensuring that elements not being deleted maintain their reference/identity in the eyes of the consumer.
Additional Context
Libraries like mobx use this observation pattern successfully. While I understand Immer aims for JSON Patch compatibility, providing an opt-in for "Rich Patches" or "Splice Patches" would make it the go-to library for distributed state management.
- 主要言語
- JavaScript
- スター
- 29k
- フォーク
- 905
- 平均マージ
- 3日 16時間
- マージ済み PR(30日)
- 22
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
immerjs/immer のほかの issue
-
Shrinking an array with `length =` and growing it back loses the patches for the truncated indices対応中かも @RClaudiuM が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 4 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
メンテナーはふだん 4 日以内に返信
-
Docs: Chinese (zh-CN) website translation is outdated vs English docs再び着手できるかも @lijiayou0728 が 91 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
immerjs/immer#1242 · コメント 5 件 ·
メンテナーはふだん 4 日以内に返信
-
question
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 4 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
immerjs/immer#1217 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Automattic/node-canvas#2633 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
capricorn86/happy-dom#2594 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
microsoft/monaco-editor#5575 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信