()
| 748 | * Loads new data from storage, compares with last known state, and applies changes |
| 749 | */ |
| 750 | const processStorageChanges = () => { |
| 751 | if (!syncParams) return |
| 752 | |
| 753 | const { begin, write, commit } = syncParams |
| 754 | |
| 755 | // Load the new data |
| 756 | const newData = loadFromStorage<T>(storageKey, storage, parser) |
| 757 | |
| 758 | // Find the specific changes |
| 759 | const changes = findChanges(lastKnownData, newData) |
| 760 | |
| 761 | if (changes.length > 0) { |
| 762 | begin() |
| 763 | changes.forEach(({ type, value }) => { |
| 764 | if (value) { |
| 765 | validateJsonSerializable(parser, value, type) |
| 766 | write({ type, value }) |
| 767 | } |
| 768 | }) |
| 769 | commit() |
| 770 | |
| 771 | // Update lastKnownData |
| 772 | lastKnownData.clear() |
| 773 | newData.forEach((storedItem, key) => { |
| 774 | lastKnownData.set(key, storedItem) |
| 775 | }) |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | const syncConfig: SyncConfig<T> & { |
| 780 | manualTrigger?: () => void |
no test coverage detected