refactor: deduplicate cache revalidation actions
This commit is contained in:
@@ -2,6 +2,7 @@ import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
|
||||
import types from '../mutation-types';
|
||||
import AttributeAPI from '../../api/attributes';
|
||||
import camelcaseKeys from 'camelcase-keys';
|
||||
import { createCacheRevalidateAction } from '../utils/cacheRevalidate';
|
||||
|
||||
export const state = {
|
||||
records: [],
|
||||
@@ -54,17 +55,10 @@ export const actions = {
|
||||
commit(types.SET_CUSTOM_ATTRIBUTE_UI_FLAG, { isFetching: false });
|
||||
}
|
||||
},
|
||||
revalidate: async ({ commit }, { newKey }) => {
|
||||
try {
|
||||
const isExistingKeyValid = await AttributeAPI.validateCacheKey(newKey);
|
||||
if (!isExistingKeyValid) {
|
||||
const response = await AttributeAPI.refetchAndCommit(newKey);
|
||||
commit(types.SET_CUSTOM_ATTRIBUTE, response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
}
|
||||
},
|
||||
revalidate: createCacheRevalidateAction({
|
||||
api: AttributeAPI,
|
||||
mutation: types.SET_CUSTOM_ATTRIBUTE,
|
||||
}),
|
||||
create: async function createAttribute({ commit }, attributeObj) {
|
||||
commit(types.SET_CUSTOM_ATTRIBUTE_UI_FLAG, { isCreating: true });
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user