Synchronization
Whenever the state changes, the store notifies Rust to keep the frontend and backend in sync. However, since data is serialized with each notification, frequent updates can be resource-intensive. One way to address this issue is by applying debouncing or throttling, making the synchronization process more efficient.
ts
function store() {
const counter = ref(0);
return {
counter,
};
}
export const useStore = defineStore('store', store, {
tauri: {
syncStrategy: 'debounce',
syncInterval: 1000,
},
});
TIP
For a detailed explanation of the differences between debouncing and throttling, take a look at this article.
While this process isn’t directly related to store persistence, it can still impact what gets saved. When the store is saved, the data written to disk comes from Rust’s cache at that moment. If the synchronization hasn’t finished yet, Rust might still be working with outdated values.