Files
chatwoot/app/javascript/dashboard/store/utils/cacheRevalidate.js
T

15 lines
481 B
JavaScript

export const createCacheRevalidateAction =
({ api, mutation, clearMutation, getData = response => response.data }) =>
async ({ commit }, { newKey }) => {
try {
const isExistingKeyValid = await api.validateCacheKey(newKey);
if (isExistingKeyValid) return;
const response = await api.refetchAndCommit(newKey);
if (clearMutation) commit(clearMutation);
commit(mutation, getData(response));
} catch (error) {
// Ignore error
}
};