Imagine you had a simple todo app using Vue and Vuex with a backend (external API, localstorage, ...).
Inside the store you hold all the todos and manage them. But when should you synchronize your store with the backend? Always? If yes, then Vuex is redundant and you can directly call the backend.
Many tutorials out there show examples like
function getTodos() {
const store = getStoreInstance();
if(!store.todos) {
store.todos = fetchTodosFromBackend();
}
return store.todos;
}
but by doing so the store would synchronize with the backend only once. Imagine the backend provides no push events and you can only ask for data or send write requests.
What are the best practices to keep the todos (which might be manuplated by other clients) in sync with the store?