File
Blob: src/client/components/canvas/tiebreak.ts
| 1 | /** |
| 2 | * Mirrors Excalidraw's own reconciler tiebreak (see `reconcileElements`): |
| 3 | * local wins when its version is strictly higher, or on a tie when its |
| 4 | * versionNonce sorts first. Exported as a pure helper so the Vitest suite |
| 5 | * can exercise the truth table without pulling in the Excalidraw bundle. |
| 6 | */ |
| 7 | export function localWinsVersionTiebreak( |
| 8 | local: { version: number; versionNonce: number }, |
| 9 | remote: { version: number; versionNonce: number } | null, |
| 10 | ): boolean { |
| 11 | if (!remote) return true; |
| 12 | if (local.version > remote.version) return true; |
| 13 | if (local.version < remote.version) return false; |
| 14 | return local.versionNonce < remote.versionNonce; |
| 15 | } |