A no-op is an array-diff operation for an item already matching the current position in the new array. The item may have reached that position naturally after other removals, additions, or moves, so no explicit movement is required. section 7.6.1
Represent a no-op with the information needed to reconcile nested items:
- Use an operation object with op: 'noop', the item, its current index, and its original index. section 7.6.1
- Detect it when the old and new items at the current index match through the configured equality function. section 7.6.4
- Preserve the old array because a no-op changes neither its items nor their current order. section 7.6.4
- Track original indices separately because earlier operations can shift an item before it becomes a no-op. section 7.6.3
Natural movement
Transforming [A, B] into [B] requires removing A. B moves from index 1 to index 0 naturally, so record a no-op for B rather than an explicit move. In a longer diff, an item such as A can similarly be recorded with its final index and saved original index after preceding operations shift it. section 7.6.1 section 7.6.3
[
{op: 'remove', index: 0, item: 'A'}
{op: 'move', originalIndex: 2, from: 1, index: 0, item: 'C'}
{op: 'noop', index: 1, originalIndex: 1, item: 'B'}
{op: 'add', index: 2, item: 'D'}
]
Inspect a complete operation sequence containing removal, move, no-op, and addition records. section 7.6.1
