( file: () => string | null, refresh: (reason: 'index' | 'disk') => void )
| 353 | * Must be called during component initialisation (it creates an `$effect`). |
| 354 | */ |
| 355 | export function liveRefresh( |
| 356 | file: () => string | null, |
| 357 | refresh: (reason: 'index' | 'disk') => void |
| 358 | ): void { |
| 359 | let seenIndex = indexTick; |
| 360 | let seenDisk = diskTick; |
| 361 | $effect(() => { |
| 362 | const index = live.indexTick; |
| 363 | const disk = live.diskTick; |
| 364 | const path = file(); |
| 365 | untrack(() => { |
| 366 | if (index !== seenIndex) { |
| 367 | seenIndex = index; |
| 368 | // An index event supersedes any disk event before it: the sync that |
| 369 | // just landed is what those edits became. |
| 370 | seenDisk = disk; |
| 371 | refresh('index'); |
| 372 | return; |
| 373 | } |
| 374 | if (disk !== seenDisk) { |
| 375 | seenDisk = disk; |
| 376 | if (touchesFile(path)) refresh('disk'); |
| 377 | } |
| 378 | }); |
| 379 | }); |
| 380 | } |
nothing calls this directly
no test coverage detected