| 23 | * @internal |
| 24 | */ |
| 25 | export class IncrementalSetConstructor<T> { |
| 26 | /** |
| 27 | * The next value of the set. |
| 28 | * |
| 29 | * @internal |
| 30 | */ |
| 31 | private nextValue?: Set<T> |
| 32 | |
| 33 | /** |
| 34 | * The diff of the set. |
| 35 | * |
| 36 | * @internal |
| 37 | */ |
| 38 | private diff?: CollectionDiff<T> |
| 39 | |
| 40 | constructor( |
| 41 | /** |
| 42 | * The previous value of the set. |
| 43 | * |
| 44 | * @internal |
| 45 | * @readonly |
| 46 | */ |
| 47 | private readonly previousValue: Set<T> |
| 48 | ) {} |
| 49 | |
| 50 | /** |
| 51 | * Gets the result of the incremental set construction if any changes were made. |
| 52 | * Returns undefined if no additions or removals occurred. |
| 53 | * |
| 54 | * @returns An object containing the final set value and the diff of changes, |
| 55 | * or undefined if no changes were made |
| 56 | * |
| 57 | * @example |
| 58 | * ```ts |
| 59 | * const constructor = new IncrementalSetConstructor(new Set(['a', 'b'])) |
| 60 | * constructor.add('c') |
| 61 | * |
| 62 | * const result = constructor.get() |
| 63 | * // result = { |
| 64 | * // value: Set(['a', 'b', 'c']), |
| 65 | * // diff: { added: Set(['c']) } |
| 66 | * // } |
| 67 | * ``` |
| 68 | * |
| 69 | * @public |
| 70 | */ |
| 71 | public get() { |
| 72 | const numRemoved = this.diff?.removed?.size ?? 0 |
| 73 | const numAdded = this.diff?.added?.size ?? 0 |
| 74 | if (numRemoved === 0 && numAdded === 0) { |
| 75 | return undefined |
| 76 | } |
| 77 | return { value: this.nextValue!, diff: this.diff! } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Add an item to the set. |
| 82 | * |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…