| 44 | |
| 45 | /** Ein neuer Schritt. Gleicht er dem aktuellen, bleibt alles, wie es ist. */ |
| 46 | export function pushNavigation<T>(history: NavigationHistory<T>, entry: T, options: NavigationHistoryOptions<T>): NavigationHistory<T> { |
| 47 | const current = history.entries[history.index]; |
| 48 | if (current !== undefined && options.key(current) === options.key(entry)) return history; |
| 49 | const limit = Math.max(1, options.limit ?? NAVIGATION_HISTORY_LIMIT); |
| 50 | const kept = [...history.entries.slice(0, history.index + 1), entry]; |
| 51 | const entries = kept.slice(Math.max(0, kept.length - limit)); |
| 52 | return { entries, index: entries.length - 1, recent: visit(history.recent, entry, options) }; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Den aktuellen Eintrag ersetzen statt einen Schritt abzulegen (K27): fuer |