( existingEntries: ConsoleEntry[] = [], incomingEntries: ConsoleEntry[] = [] )
| 111 | } |
| 112 | |
| 113 | function mergeEntries( |
| 114 | existingEntries: ConsoleEntry[] = [], |
| 115 | incomingEntries: ConsoleEntry[] = [] |
| 116 | ): ConsoleEntry[] { |
| 117 | const entriesById = new Map<string, ConsoleEntry>() |
| 118 | const orderedIds: string[] = [] |
| 119 | |
| 120 | for (const entry of existingEntries) { |
| 121 | entriesById.set(entry.id, entry) |
| 122 | orderedIds.push(entry.id) |
| 123 | } |
| 124 | |
| 125 | for (const entry of incomingEntries) { |
| 126 | const existing = entriesById.get(entry.id) |
| 127 | if (!existing) { |
| 128 | entriesById.set(entry.id, entry) |
| 129 | orderedIds.push(entry.id) |
| 130 | continue |
| 131 | } |
| 132 | if (shouldReplaceEntry(existing, entry)) { |
| 133 | entriesById.set(entry.id, entry) |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | return orderedIds |
| 138 | .map((id) => entriesById.get(id)) |
| 139 | .filter((entry): entry is ConsoleEntry => !!entry) |
| 140 | } |
| 141 | |
| 142 | function mergePersistedConsoleData( |
| 143 | existing: PersistedConsoleData | null, |
no test coverage detected