vuex#ActionTree TypeScript Examples
The following examples show how to use
vuex#ActionTree.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: staff.ts From Corsace with MIT License | 6 votes |
actions: ActionTree<StaffState, RootState> = {
async setMca ({ commit }, year: number) {
const { data } = await this.$axios.get(`/api/staff/${year}`);
if (!data.error) {
commit("setMca", data);
}
},
async setInitialData ({ dispatch }, year: number) {
await dispatch("setMca", year);
},
}
Example #2
Source File: dashboard.ts From ant-design-vue3-admin with MIT License | 6 votes |
actions: ActionTree<State, State> & Actions = {
async [ActionTypes.OVERVIEW]({ commit }) {
const { data } = await this.$request.get(OVERVIEW_URL);
commit(MutationTypes.SET_OVERVIEW, data);
},
async [ActionTypes.WORKPLACE]({ commit }) {
const [projects, teams, movements, radarData] = await Promise.all([
await this.$request.get(PROJECT_URL),
await this.$request.get(TEAM_URL),
await this.$request.get(MOVEMENT_URL),
await this.$request.get(RADAR_URL),
]);
commit(MutationTypes.SET_PROJECT, projects.data);
commit(MutationTypes.SET_TEAM, teams.data);
commit(MutationTypes.SET_MOVEMENT, movements.data);
commit(MutationTypes.SET_RADAR, radarData.data);
},
}
Example #3
Source File: actions.ts From vue-storefront-1 with MIT License | 6 votes |
actions: ActionTree<WishlistState, RootState> = {
clear (context) {
context.commit(types.WISH_DEL_ALL_ITEMS, [])
},
async load ({ commit, getters, dispatch }, force: boolean = false) {
if (!force && getters.isWishlistLoaded) return
commit(types.SET_WISHLIST_LOADED)
const storedItems = await dispatch('loadFromCache')
commit(types.WISH_LOAD_WISH, storedItems)
},
loadFromCache () {
const wishlistStorage = StorageManager.get('wishlist')
return wishlistStorage.getItem('current-wishlist')
},
addItem ({ commit }, product) {
commit(types.WISH_ADD_ITEM, { product })
},
removeItem ({ commit }, product) {
commit(types.WISH_DEL_ITEM, { product })
}
}
Example #4
Source File: actions.ts From vue-storefront-1 with MIT License | 6 votes |
actions: ActionTree<ReviewState, RootState> = {
async list (context, { productId, approved = true, start = 0, size = 50, entityType = 'review', sort = '', excludeFields = null, includeFields = null }) {
const query = createLoadReviewsQuery({ productId, approved })
const reviewResponse = await quickSearchByQuery({ query, start, size, entityType, sort, excludeFields, includeFields })
context.commit(types.REVIEW_UPD_REVIEWS, reviewResponse)
},
async add (context, review: Review) {
EventBus.$emit('notification-progress-start', i18n.t('Adding a review ...'))
const isReviewCreated = await ReviewsService.createReview(review)
EventBus.$emit('notification-progress-stop')
if (isReviewCreated) {
EventBus.$emit('clear-add-review-form')
}
return isReviewCreated
}
}
Example #5
Source File: actions.ts From vue-storefront-1 with MIT License | 6 votes |
actions: ActionTree<RecentlyViewedState, RootState> = {
load ({ commit }) {
cacheStorage.getItem('recently-viewed', (err, storedItems) => {
if (err) throw new Error(err)
commit(types.RECENTLY_VIEWED_LOAD, storedItems)
})
},
addItem ({ commit }, product) {
commit(types.RECENTLY_VIEWED_ADD_ITEM, { product })
}
}
Example #6
Source File: actions.ts From vue-storefront-1 with MIT License | 6 votes |
actions: ActionTree<CompareState, RootState> = {
async load ({ commit, getters, dispatch }, force: boolean = false) {
if (force || !getters.isCompareLoaded) {
commit(types.SET_COMPARE_LOADED)
const storedItems = await dispatch('fetchCurrentCompare')
if (storedItems) {
commit(types.COMPARE_LOAD_COMPARE, storedItems)
Logger.info('Compare state loaded from browser cache: ', 'cache', storedItems)()
}
if (config.entities.attribute.loadByAttributeMetadata) {
dispatch(
'attribute/loadProductAttributes',
{ products: getters.getCompareItems, merge: true },
{ root: true }
)
}
}
},
async fetchCurrentCompare () {
const cacheStorage = StorageManager.get('compare')
return cacheStorage.getItem('current-compare')
},
async addItem ({ commit }, product) {
commit(types.COMPARE_ADD_ITEM, { product })
},
async removeItem ({ commit }, product) {
commit(types.COMPARE_DEL_ITEM, { product })
},
async clear ({ commit }) {
commit(types.COMPARE_LOAD_COMPARE, [])
}
}
Example #7
Source File: actions.ts From vue-storefront-1 with MIT License | 6 votes |
actions: ActionTree<CmsHierarchyState, RootState> = {
list (context, { id, entityType = 'cms_hierarchy', excludeFields = null, includeFields = null }) {
return quickSearchByQuery({
query: createHierarchyLoadQuery({ id }),
entityType,
excludeFields,
includeFields
})
}
}
Example #8
Source File: index.ts From vue-storefront-1 with MIT License | 6 votes |
actions: ActionTree<CartState, RootState> = { ...connectActions, ...itemActions, ...couponActions, ...mergeActions, ...methodsActions, ...productActions, ...quantityActions, ...synchronizeActions, ...totalsActions }
Example #9
Source File: actions.ts From vue3-cesium-typescript-start-up-template with MIT License | 6 votes |
actions: ActionTree<Tool3DTileState, RootState> = {
async [Tool3DTileActionTypes.RESET_STATE]({ commit }) {
commit(Tool3DTileMutationTypes.RESET_STATE)
},
async [Tool3DTileActionTypes.SET_HIGHLIGHT_3DTILE_FEATURE_ACTIVE](
{ commit },
payload: boolean
) {
commit(Tool3DTileMutationTypes.SET_HIGHLIGHT_3DTILE_FEATURE_ACTIVE, payload)
},
async [Tool3DTileActionTypes.SET_HOVER_CLASSIFICATION_ACTIVE](
{ commit },
payload: boolean
) {
commit(Tool3DTileMutationTypes.SET_HOVER_CLASSIFICATION_ACTIVE, payload)
},
async [Tool3DTileActionTypes.SET_CLICK_CLASSIFICATION_ACTIVE](
{ commit },
payload: boolean
) {
commit(Tool3DTileMutationTypes.SET_CLICK_CLASSIFICATION_ACTIVE, payload)
},
}
Example #10
Source File: actions.ts From vue3-cesium-typescript-start-up-template with MIT License | 6 votes |
actions: ActionTree<OtherState, RootState> = {
async [OtherActionTypes.RESET_STATE]({ commit }) {
commit(OtherMutationTypes.RESET_STATE)
},
// other
async [OtherActionTypes.SWITCH_DEPTH_TEST_AGAINST_TERRAIN](
{ commit, state },
options: ClickHandlerOption
) {
const { viewer } = options
if (!viewer) {
return
}
const switchTo = !state.depthTestAgainstTerrain
viewer.scene.globe.depthTestAgainstTerrain = switchTo
commit(OtherMutationTypes.SET_DEPTH_TEST_AGAINST_TERRAIN, switchTo)
},
}
Example #11
Source File: actions.ts From vue3-cesium-typescript-start-up-template with MIT License | 6 votes |
actions: ActionTree<MeasureState, RootState> = {
async [MeasureActionTypes.RESET_STATE]({ commit }) {
commit(MeasureMutationTypes.RESET_STATE)
},
// measure
async [MeasureActionTypes.SET_MEASURE_POINT_ACTIVE](
{ commit },
payload: boolean
) {
commit(MeasureMutationTypes.SET_MEASURE_POINT_ACTIVE, payload)
},
async [MeasureActionTypes.SET_MEASURE_POLYLINE_ACTIVE](
{ commit },
payload: boolean
) {
commit(MeasureMutationTypes.SET_MEASURE_POLYLINE_ACTIVE, payload)
},
async [MeasureActionTypes.SET_MEASURE_POLYGON_ACTIVE](
{ commit },
payload: boolean
) {
commit(MeasureMutationTypes.SET_MEASURE_POLYGON_ACTIVE, payload)
},
}
Example #12
Source File: actions.ts From vue3-cesium-typescript-start-up-template with MIT License | 6 votes |
actions: ActionTree<ImageryState, RootState> = {
async [ImageryActionTypes.RESET_STATE]({ commit }) {
commit(ImageryMutationTypes.RESET_STATE)
},
// imagery
async [ImageryActionTypes.SET_SPLIT]({ commit, state }, payload: SplitType) {
commit(ImageryMutationTypes.SET_SPLIT, payload)
},
}
Example #13
Source File: actions.ts From vue3-cesium-typescript-start-up-template with MIT License | 6 votes |
actions: ActionTree<DrawState, RootState> = {
async [DrawActionTypes.RESET_STATE]({ commit }) {
commit(DrawMutationTypes.RESET_STATE)
},
// draw
async [DrawActionTypes.SET_DRAW_POINT_ACTIVE]({ commit }, payload: boolean) {
commit(DrawMutationTypes.SET_DRAW_POINT_ACTIVE, payload)
},
async [DrawActionTypes.SET_DRAW_POLYLINE_ACTIVE](
{ commit },
payload: boolean
) {
commit(DrawMutationTypes.SET_DRAW_POLYLINE_ACTIVE, payload)
},
async [DrawActionTypes.SET_DRAW_POLYGON_ACTIVE](
{ commit },
payload: boolean
) {
commit(DrawMutationTypes.SET_DRAW_POLYGON_ACTIVE, payload)
},
}
Example #14
Source File: actions.ts From vue3-cesium-typescript-start-up-template with MIT License | 6 votes |
actions: ActionTree<State, RootState> = {
async [ToolbarActionTypes.RESET_STATE]({ commit }) {
commit(ToolbarMutationTypes.RESET_STATE)
},
async [ToolbarActionTypes.SET_VISIBLE]({ commit }, payload: boolean) {
commit(ToolbarMutationTypes.SET_VISIBLE, payload)
},
async [ToolbarActionTypes.SET_DROP_DOWN]({ commit }, payload: DropdownState) {
commit(ToolbarMutationTypes.SET_DROP_DOWN, payload)
},
// elevation contour
async [ToolbarActionTypes.SET_ELEVATION_CONTURE_ACTIVE](
{ commit },
payload: boolean
) {
commit(ToolbarMutationTypes.SET_ELEVATION_CONTURE_ACTIVE, payload)
},
// terrain sampling
async [ToolbarActionTypes.SET_TERRAIN_SAMPLING](
{ commit },
payload: TerrainSamplingState
) {
commit(ToolbarMutationTypes.SET_TERRAIN_SAMPLING, payload)
},
}
Example #15
Source File: actions.ts From vue3-cesium-typescript-start-up-template with MIT License | 6 votes |
actions: ActionTree<State, RootState> = {
async [LocationBarActionTypes.RESET_STATE]({ commit }) {
commit(LocationBarMutationTypes.RESET_STATE)
},
async [LocationBarActionTypes.SET_SHOW_CAMERA_LOCATION](
{ commit },
payload: boolean
) {
commit(LocationBarMutationTypes.SET_SHOW_CAMERA_LOCATION, payload)
},
async [LocationBarActionTypes.SET_SHOW_MOUSE_LOCATION](
{ commit },
payload: boolean
) {
commit(LocationBarMutationTypes.SET_SHOW_MOUSE_LOCATION, payload)
},
async [LocationBarActionTypes.SET_SHOW_FPS]({ commit }, payload: boolean) {
commit(LocationBarMutationTypes.SET_SHOW_FPS, payload)
},
}
Example #16
Source File: actions.ts From vue3-cesium-typescript-start-up-template with MIT License | 6 votes |
actions: ActionTree<JTPrimitiveState, RootState> = {
async [JTPrimitiveActionTypes.RESET_STATE]({ commit }) {
commit(JTPrimitiveMutationTypes.RESET_STATE)
},
// Primitive
async [JTPrimitiveActionTypes.SYNC_JTPRIMITIVES](
{ commit, state },
payload: Cesium.Viewer
) {
if (!payload) {
return
}
const pris = payload.jt?.primitiveManager.syncJTPrimitives()
commit(JTPrimitiveMutationTypes.SYNC_JTPRIMITIVES, pris)
},
}
Example #17
Source File: influences.ts From Corsace with MIT License | 6 votes |
actions: ActionTree<InfluenceState, RootState> = {
async search ({ state, commit, rootState }, value) {
const user = state.users.find(u => u.osu.userID === value);
if (user) {
if (!state.root) {
commit("setRoot", user);
}
return;
}
try {
const {data} = await this.$axios.get(`/api/influences?user=${value}&year=${rootState.mca?.year}&mode=${rootState.selectedMode}`);
if (!data.error) {
commit("addUser", data);
if (!state.root) {
commit("setRoot", data);
}
}
} catch (error) {
console.log(error);
}
},
findUser ({ state }, userId) {
return state.users.find(u => u.osu.userID == userId);
},
resetRoot ({ commit }) {
commit("resetRoot");
},
}
Example #18
Source File: staff.ts From Corsace with MIT License | 6 votes |
actions: ActionTree<StaffState, RootState> = {
async setMca ({ commit }, year: number) {
const { data } = await this.$axios.get(`/api/staff/${year}`);
if (!data.error) {
commit("setMca", data);
}
},
async setCategories ({ commit }, year: number) {
const { data } = await this.$axios.get(`/api/staff/categories/${year}`);
if (!data.error) {
commit("setCategories", data);
}
},
async setRequests ({ commit }, year: number) {
const { data } = await this.$axios.get(`/api/staff/requests/${year}`);
if (!data.error) {
commit("setRequests", data);
}
},
async setInitialData ({ dispatch }, year: number) {
await Promise.all([
dispatch("setMca", year),
dispatch("setCategories", year),
dispatch("setRequests", year),
]);
},
async updateRequest ({ commit }, payload: UpdateRequestData) {
const { data } = await this.$axios.post(`/api/staff/requests/${payload.id}/update`, {
status: payload.status,
});
if (!data.error) {
commit("updateRequest", payload);
}
},
}
Example #19
Source File: index.ts From master-frontend-lemoncode with MIT License | 6 votes |
actions: ActionTree<CartState, unknown> & CartActions = {
[CartActionEnums.ADD_ITEM_TO_CART]: (
{ commit }: ActionContext<CartState, unknown>,
payload: Product
) => {
if (!payload) return
commit(CartMutationsEnums.ADD_ITEM_TO_CART, payload)
},
}
Example #20
Source File: index.ts From master-frontend-lemoncode with MIT License | 6 votes |
actions: ActionTree<ICartState, unknown> & CartActionsType = {
[CartActionEnums.ADD_ITEM_TO_CART](
{ commit }: ActionContext<ICartState, unknown>,
product: Product
) {
if (!product) return
commit(CartMutationEnums.ADD_ITEM_TO_CART, product)
},
[CartActionEnums.REMOVE_ITEM_FROM_CART](
{ commit }: ActionContext<ICartState, unknown>,
id: Product['id']
) {
if (!id) return
commit(CartMutationEnums.REMOVE_ITEM_FROM_CART, id)
},
[CartActionEnums.DECREMENT_QUANTITY](
{ commit }: ActionContext<ICartState, unknown>,
id: Product['id']
) {
if (!id) return
commit(CartMutationEnums.DECREMENT_QUANTITY, id)
},
}
Example #21
Source File: index.ts From Corsace with MIT License | 6 votes |
actions: ActionTree<RootState, RootState> = {
async setLoggedInUser ({ commit }) {
const { data } = await this.$axios.get(`/api/user`);
if (!data.error) {
commit("setLoggedInUser", data);
}
},
async setInitialData ({ dispatch }) {
await Promise.all([
dispatch("setLoggedInUser"),
]);
},
}
Example #22
Source File: index.ts From ant-design-vue3-admin with MIT License | 5 votes |
actions: ActionTree<State, State> & Actions = {
async [ActionTypes.LOGIN]({ commit }, payload: LoginParams) {
const { data } = await this.$request.post(LOGIN_URL, payload);
if (data) {
commit(MutationTypes.SET_USERINFO, data);
Cookies.set(userToken, data.id.toString(), {
expires: 1,
});
}
},
async [ActionTypes.QUERY]({ commit }, id: number) {
const { data } = await this.$request.get(QUERY_URL, { params: { id } });
if (data) {
commit(MutationTypes.SET_USERINFO, data);
}
},
async [ActionTypes.NOTIFICATION]({ commit }) {
const { data } = await this.$request.get(NOTIFICATION_URL);
if (data) {
commit(MutationTypes.SET_NOTIFICATION, data);
}
},
async [ActionTypes.MENU]({ commit }, locale: string) {
const { data } = await this.$request.get(MENU_URL, { params: { locale } });
if (data) {
commit(MutationTypes.SET_MENU, data);
let userMenu: Menu[] = [];
data.forEach((item: Menu) => {
if (!item.permissionCode || state.userInfo.permissions?.includes(item.permissionCode)) {
userMenu.push(item);
}
if (item.children) {
item.children = item.children.filter(
(child: Menu) =>
!child.permissionCode || state.userInfo.permissions?.includes(child.permissionCode)
);
}
});
commit(MutationTypes.SET_USER_MENU, userMenu);
}
},
}
Example #23
Source File: actions.ts From vue3-cesium-typescript-start-up-template with MIT License | 5 votes |
actions: ActionTree<State, RootState> = {
async [LayoutActionTypes.RESET_STATE]({ commit }) {
commit(LayoutMutationTypes.RESET_STATE)
},
async [LayoutActionTypes.SET_SHOW_BROWSER_PANEL](
{ commit },
payload: boolean
) {
commit(LayoutMutationTypes.SET_SHOW_BROWSER_PANEL, payload)
},
async [LayoutActionTypes.SET_SHOW_TOOLBAR]({ commit }, payload: boolean) {
commit(LayoutMutationTypes.SET_SHOW_TOOLBAR, payload)
},
async [LayoutActionTypes.SET_SHOW_SETTING_BUTTON](
{ commit },
payload: boolean
) {
commit(LayoutMutationTypes.SET_SHOW_SETTING_BUTTON, payload)
},
async [LayoutActionTypes.SET_TOOLBAR_HEIGHT]({ commit }, payload: number) {
commit(LayoutMutationTypes.SET_TOOLBAR_HEIGHT, payload)
},
async [LayoutActionTypes.ADD_UNIQUE_NAME_OVERLAY_DYNAMIC_VIEW_BY_NAME](
{ commit },
payload: string
) {
commit(
LayoutMutationTypes.ADD_UNIQUE_NAME_OVERLAY_DYNAMIC_VIEW_BY_NAME,
payload
)
},
async [LayoutActionTypes.REMOVE_OVERLAY_DYNAMIC_VIEW_BY_NAME](
{ commit },
payload: string
) {
commit(LayoutMutationTypes.REMOVE_OVERLAY_DYNAMIC_VIEW_BY_NAME, payload)
},
}
Example #24
Source File: actions.ts From vue-storefront-1 with MIT License | 5 votes |
actions: ActionTree<RootState, RootState> = {
async resetUserInvalidateLock ({ commit }) {
commit(types.USER_TOKEN_INVALIDATE_LOCK_CHANGED, 0)
},
async resetUserInvalidation ({ commit }) {
commit(types.RESET_USER_TOKEN_INVALIDATION)
}
}
Example #25
Source File: index.ts From Corsace with MIT License | 5 votes |
actions: ActionTree<RootState, RootState> = {
async setLoggedInUser ({ commit }) {
const { data } = await this.$axios.get(`/api/mca/user`);
if (!data.error) {
commit("setLoggedInUser", data);
}
},
async setMCA ({ commit }, year: number) {
const { data } = await this.$axios.get(`/api/mca?year=${year}`);
if (!data.error) {
commit("setMCA", data);
} else {
const { data } = await this.$axios.get(`/api/mca/all`);
commit("setMCA", {});
commit("setAllMCA", data);
}
},
async setInitialData ({ dispatch }, year: number) {
await Promise.all([
dispatch("setLoggedInUser"),
dispatch("setMCA", year),
]);
},
setSelectedMode ({ commit }) {
commit("setSelectedMode");
},
updateSelectedMode ({ commit }, mode) {
commit("updateSelectedMode", mode);
},
async submitGuestRequest ({ commit, state }, payload: GuestRequestPayload) {
if (!state.mca) return;
const { data } = await this.$axios.post(`/api/guestRequests/create`, {
mode: payload.mode,
url: payload.url,
});
if (data.error) {
alert(data.error);
return;
}
commit("addGuestRequest", data);
},
async updateGuestRequest ({ commit, state }, payload: UpdateGuestRequestPayload) {
if (!state.mca) return;
const { data } = await this.$axios.post(`/api/guestRequests/${payload.id}/update`, {
mode: payload.mode,
url: payload.url,
});
if (data.error) {
alert(data.error);
return;
}
commit("updateGuestRequest", data);
},
}
Example #26
Source File: actions.ts From vue-storefront-1 with MIT License | 5 votes |
actions: ActionTree<CmsPageState, RootState> = {
async list ({ commit }, { filterValues = null, filterField = 'identifier', size = 150, start = 0, excludeFields = null, includeFields = null, skipCache = false }) {
let query = createPageLoadingQuery({ filterField, filterValues })
const pageResponse = await quickSearchByQuery({ query, entityType: 'cms_page', excludeFields, includeFields })
commit(types.CMS_PAGE_UPDATE_CMS_PAGES, pageResponse.items)
return pageResponse.items
},
async single ({ getters, commit, dispatch }, { key = 'identifier', value, excludeFields = null, includeFields = null, skipCache = false, setCurrent = true }) {
const currentItems = getters.findItems({ key, value })
if (skipCache || !getters.hasItems || !currentItems) {
const pageResponse = await quickSearchByQuery({
query: createSinglePageLoadQuery({ key, value }),
entityType: 'cms_page',
excludeFields,
includeFields
})
if (pageResponse && pageResponse.items && pageResponse.items.length > 0) {
commit(types.CMS_PAGE_ADD_CMS_PAGE, pageResponse.items[0])
if (setCurrent) commit(types.CMS_PAGE_SET_CURRENT, pageResponse.items[0])
return pageResponse.items[0]
}
throw new Error('CMS query returned empty result')
}
if (currentItems) {
if (setCurrent) {
commit(types.CMS_PAGE_SET_CURRENT, currentItems)
}
return currentItems
}
},
async loadFromCache ({ commit }, { key, value, setCurrent }) {
const cmsStorage = StorageManager.get('cms')
const storedItems = await cmsStorage.getItem(cmsPagesStorageKey)
if (storedItems) {
commit(types.CMS_PAGE_UPDATE_CMS_PAGES, storedItems)
const resp = storedItems.find(p => p[key] === value)
if (!resp) {
throw new Error('CMS query returned empty result')
}
if (setCurrent) {
commit(types.CMS_PAGE_SET_CURRENT, resp)
}
return resp
}
throw new Error('CMS query returned empty result')
},
addItem ({ commit }, page) {
commit(types.CMS_PAGE_ADD_CMS_PAGE, page)
}
}
Example #27
Source File: index.ts From vueconf-london with MIT License | 5 votes |
actions: ActionTree<State, State> & Actions = {
async [ActionTypes.SAMPLE_ACTION]({ commit, dispatch }, payload) {
console.log("Sample Action called with payload:", payload)
return `${payload} ${payload}`
},
}
Example #28
Source File: actions.ts From vue-storefront-1 with MIT License | 5 votes |
actions: ActionTree<CmsBlockState, RootState> = {
async list ({ getters, commit }, { filterValues = null, filterField = 'identifier', size = 150, start = 0, excludeFields = null, includeFields = null, skipCache = false }) {
if (skipCache || !getters.hasItems) {
const blockResponse = await quickSearchByQuery({
query: createLoadingBlockQuery({ filterField, filterValues }),
entityType: 'cms_block',
size,
start,
excludeFields,
includeFields
})
commit(types.CMS_BLOCK_UPDATE_CMS_BLOCKS, blockResponse.items)
return blockResponse.items
}
return getters.getCmsBlocks
},
async single ({ getters, commit }, { key = 'identifier', value, excludeFields = null, includeFields = null, skipCache = false }) {
let cmsBlock = getters.findCmsBlocks({ key, value })
if (skipCache || cmsBlock.length === 0) {
const blockResponse = await quickSearchByQuery({
query: createSingleBlockQuery({ key, value }),
entityType: 'cms_block',
excludeFields,
includeFields
})
if (blockResponse.items.length > 0) {
const items = blockResponse.items.filter(item => item[key] === value)
commit(types.CMS_BLOCK_ADD_CMS_BLOCK, items[0])
return items[0]
}
}
return cmsBlock[0]
},
addItem ({ commit }, block) {
commit(types.CMS_BLOCK_ADD_CMS_BLOCK, block)
}
}
Example #29
Source File: actions.ts From vue-storefront-1 with MIT License | 5 votes |
actions: ActionTree<TaxState, RootState> = {
async list ({ state, commit, dispatch }, { entityType = 'taxrule' }) {
if (state.rules.length > 0) {
Logger.info('Tax rules served from local memory', 'tax')()
return { items: state.rules }
}
const resp = await quickSearchByQuery({ query: new SearchQuery(), entityType })
dispatch('storeToRulesCache', { items: resp.items })
commit(types.TAX_UPDATE_RULES, resp)
return resp
},
storeToRulesCache (context, { items }) {
const cache = StorageManager.get('elasticCache')
for (let tc of items) {
const cacheKey = entityKeyName('tc', tc.id)
cache.setItem(cacheKey, tc).catch((err) => {
Logger.error('Cannot store cache for ' + cacheKey + ', ' + err)()
})
}
},
single ({ getters }, { productTaxClassId }) {
return getters.getRules.find((e) =>
e.product_tax_class_ids.indexOf(parseInt(productTaxClassId)) >= 0
)
},
async calculateTaxes ({ dispatch, getters, rootState }, { products }) {
const mutatedProducts = catalogHooksExecutors.beforeTaxesCalculated(products)
if (config.tax.calculateServerSide) {
Logger.debug('Taxes calculated server side, skipping')()
return doPlatformPricesSync(mutatedProducts)
}
let storeView = currentStoreView()
const tcs = await dispatch('list', {})
const {
defaultCountry,
defaultRegion,
sourcePriceIncludesTax,
finalPriceIncludesTax,
deprecatedPriceFieldsSupport
} = storeView.tax
const recalculatedProducts = mutatedProducts.map(product =>
calculateProductTax({
product,
taxClasses: tcs.items,
taxCountry: defaultCountry,
taxRegion: defaultRegion,
finalPriceInclTax: finalPriceIncludesTax,
sourcePriceInclTax: sourcePriceIncludesTax,
userGroupId: getters.getUserTaxGroupId,
deprecatedPriceFieldsSupport: deprecatedPriceFieldsSupport,
isTaxWithUserGroupIsActive: getters.getIsUserGroupedTaxActive
})
)
return doPlatformPricesSync(recalculatedProducts)
}
}