All files / src/internal revision.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                          2494002x   2494002x       862919x         10710306x 10710306x      
// Change tracking: the single path every change to a collection goes through.
 
/**
 * Counts changes to a collection.
 *
 * `revision` changes on every change to contents (the public value watchers read); `structure`
 * changes only when elements are added or removed (what fail-fast iterators and `removeIf`
 * compare, so replacing a value in place does not invalidate them).
 *
 * @internal
 */
export class ChangeCounter {
  /** Changes on every change to contents. */
  revision = 0
  /** Changes when elements are added or removed. */
  structure = 0
 
  /** Records a change that replaced an element or value without adding or removing one. */
  replaced(): void {
    this.revision++
  }
 
  /** Records a change that added or removed elements. */
  structural(): void {
    this.revision++
    this.structure++
  }
}