vuex#GetterTree TypeScript Examples
The following examples show how to use
vuex#GetterTree.
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: getters.ts From vue-storefront-1 with MIT License | 6 votes |
getters: GetterTree<CartState, RootState> = {
getCartToken: state => state.cartServerToken,
getLastSyncDate: state => state.cartServerLastSyncDate,
getLastTotalsSyncDate: state => state.cartServerLastTotalsSyncDate,
getShippingMethod: state => state.shipping,
getPaymentMethod: state => state.payment,
getLastCartHash: state => state.cartItemsHash,
getCurrentCartHash: state => calcItemsHmac(state.cartItems, state.cartServerToken),
isCartHashChanged: (state, getters) => getters.getCurrentCartHash !== state.cartItemsHash,
isSyncRequired: (state, getters) => getters.isCartHashEmptyOrChanged || !state.cartServerLastSyncDate,
isTotalsSyncRequired: (state, getters) => getters.isCartHashEmptyOrChanged || !state.cartServerLastTotalsSyncDate,
isCartHashEmptyOrChanged: (state, getters) => !state.cartItemsHash || getters.isCartHashChanged,
getCartItems: state => state.cartItems,
isTotalsSyncEnabled: () => config.cart.synchronize_totals && onlineHelper.isOnline && !isServer,
isCartConnected: state => !!state.cartServerToken,
isCartSyncEnabled: () => config.cart.synchronize && onlineHelper.isOnline && !isServer,
getFirstShippingMethod: state => state.shipping instanceof Array ? state.shipping[0] : state.shipping,
getFirstPaymentMethod: state => state.payment instanceof Array ? state.payment[0] : state.payment,
getTotals: ({ cartItems, platformTotalSegments }, getters) =>
(platformTotalSegments && onlineHelper.isOnline) ? platformTotalSegments : calculateTotals(getters.getFirstShippingMethod, getters.getFirstPaymentMethod, cartItems),
getItemsTotalQuantity: ({ cartItems }) => config.cart.minicartCountType === 'items' ? cartItems.length : sumBy(cartItems, p => p.qty),
getCoupon: ({ platformTotals }): AppliedCoupon | false =>
!(platformTotals && platformTotals.hasOwnProperty('coupon_code')) ? false : { code: platformTotals.coupon_code, discount: platformTotals.discount_amount },
isVirtualCart: ({ cartItems }) => cartItems.length ? cartItems.every(itm => itm.type_id === 'downloadable' || itm.type_id === 'virtual') : false,
canUpdateMethods: (state, getters) => getters.isCartSyncEnabled && getters.isCartConnected,
canSyncTotals: (state, getters) => getters.isTotalsSyncEnabled && getters.isCartConnected,
isCartEmpty: state => state.cartItems.length === 0,
bypassCounter: state => state.connectBypassCount,
getShippingMethodCode: state => state.shipping && state.shipping.method_code,
getPaymentMethodCode: state => state.payment && state.payment.code,
getIsAdding: state => state.isAddingToCart,
getIsMicroCartOpen: state => state.isMicrocartOpen
}
Example #2
Source File: getters.ts From vue-storefront-1 with MIT License | 6 votes |
getters: GetterTree<UserState, RootState> = {
isLoggedIn (state) {
return state.current !== null
},
isLocalDataLoaded: state => state.local_data_loaded,
getUserToken (state) {
return state.token
},
getOrdersHistory (state) {
return state.orders_history ? state.orders_history.items : []
},
getToken (state) {
return state.token
},
getUserEmail (state, getters) {
return getters.isLoggedIn ? state.current.email : null
}
}
Example #3
Source File: stage.ts From Corsace with MIT License | 6 votes |
getters: GetterTree<StageState, RootState> = {
relatedCandidacies (state): Vote[] | Nomination[] {
if (!state.selectedCategory) return [];
const arr = state.stage === "nominating" ? state.nominations : state.votes;
// Type doesnt here
return (arr as Vote[]).filter(v => v.category.ID === state.selectedCategory?.id);
},
categoriesInfo (state): CategoryStageInfo[] {
if (state.stage === "voting") {
return state.categories.map(c => {
const info = {
...c,
count: state.votes.filter(v => v.category.ID === c.id).length,
};
info.maxNominations = 100;
return info;
});
}
return state.categories.map(c => ({
...c,
count: state.nominations.filter(n => n.category.ID === c.id).length,
}));
},
}
Example #4
Source File: getters.ts From vue-storefront-1 with MIT License | 6 votes |
getters: GetterTree<AttributeState, RootState> = {
getAttributeListByCode: (state) => state.list_by_code,
getAttributeListById: (state) => state.list_by_id,
// @deprecated
attributeListByCode: (state, getters) => getters.getAttributeListByCode,
// @deprecated
attributeListById: (state, getters) => getters.getAttributeListById,
getBlacklist: (state) => state.blacklist,
getAllComparableAttributes: (state, getters) => {
const attributesByCode = getters.getAttributeListByCode
return Object.values(attributesByCode).filter((a: any) => ['1', true].includes(a.is_comparable)) // In some cases we get boolean instead of "0"/"1" that why we support both options
}
}
Example #5
Source File: getters.ts From vue-storefront-1 with MIT License | 6 votes |
getters: GetterTree<CategoryState, RootState> = {
getCurrentCategory: state => state.current,
getCurrentCategoryPath: state => state.current_path,
getAllCategoryFilters: state => state.filters,
getActiveCategoryFilters: state => state.filters.chosen,
getAvailableCategoryFilters: state => state.filters.available,
getCurrentCategoryProductQuery: state => state.current_product_query,
getCategories: state => state.list,
getCategoryBreadcrumbs: state => state.breadcrumbs,
/**
* @deprecated use getCurrentCategory instead
*/
current: (state, getters) => getters.getCurrentCategory,
/**
* @deprecated use getCategories instead
*/
list: (state, getters) => getters.getCategories
}
Example #6
Source File: getters.ts From vue-storefront-1 with MIT License | 6 votes |
getters: GetterTree<CmsPageState, RootState> = {
cmsPages: (state, getters) => {
Logger.error('The getter cmsPage/cmsPages has been deprecated please change to cmsPage/getCmsPages')()
return getters.getCmsPages
},
getCmsPages: (state) => state.items,
hasItems: (state) => state.items && state.items.length > 0,
findItems: (state) => ({ key, value }) => state.items.find(p => p[key] === value)
}
Example #7
Source File: index.ts From master-frontend-lemoncode with MIT License | 6 votes |
getters: GetterTree<ICartState, unknown> & ICartGetters = {
items: (state: ICartState) => state.items,
totalItemsInCart: (state: ICartState) => {
const cartItems: CartItem[] = Object.values(state.items || {})
return cartItems.reduce((acc: number, item: CartItem) => {
return item.quantity + acc
}, 0)
},
}
Example #8
Source File: index.ts From master-frontend-lemoncode with MIT License | 6 votes |
getters: GetterTree<CartState, unknown> & CartGetters = {
totalItemsInCart: (state: CartState) => {
const cartItems: CartItem[] = Object.values(state.items)
return cartItems.reduce(
(acc: number, current: CartItem) => acc + current.quantity,
0
)
},
}
Example #9
Source File: getters.ts From vue-storefront-1 with MIT License | 6 votes |
getters: GetterTree<CmsBlockState, RootState> = {
// @deprecated
cmsBlocks: (state, getters) => getters.getCmsBlocks,
// @deprecated
cmsBlockIdentifier: (state, getters) => (identifier) => getters.getCmsBlockByIdentifier(identifier),
// @deprecated
cmsBlockId: (state, getters) => (id) => getters.getCmsBlockById(id),
getCmsBlockByIdentifier: (state) => (identifier) =>
state.items.find(item => typeof item === 'object' && item.identifier === identifier),
getCmsBlockById: (state) => (id) => state.items.find(item => item.id === id),
getCmsBlocks: (state) => state.items,
hasItems: (state) => state.items && state.items.length > 0,
findCmsBlocks: (state) => ({ key, value }) => state.items.filter(item => item[key] === value)
}
Example #10
Source File: getters.ts From vue-storefront-1 with MIT License | 6 votes |
getters: GetterTree<CheckoutState, RootState> = {
getShippingDetails: (state, getters, rootState) => {
if (!state.shippingDetails.country) {
return { ...state.shippingDetails, country: rootState.storeView.tax.defaultCountry }
}
return state.shippingDetails
},
getPersonalDetails: state => state.personalDetails,
getPaymentDetails: state => state.paymentDetails,
isThankYouPage: state => state.isThankYouPage,
getModifiedAt: state => state.modifiedAt,
isUserInCheckout: state => ((Date.now() - state.modifiedAt) <= (60 * 30 * 1000)),
getPaymentMethods: (state, getters, rootState, rootGetters) => {
const isVirtualCart = rootGetters['cart/isVirtualCart']
return state.paymentMethods.filter(method => !isVirtualCart || method.code !== 'cashondelivery')
},
getDefaultPaymentMethod: (state, getters) => getters.getPaymentMethods.find(item => item.default),
getNotServerPaymentMethods: (state, getters) =>
getters.getPaymentMethods.filter((itm) =>
(typeof itm !== 'object' || !itm.is_server_method)
),
getShippingMethods: state => state.shippingMethods,
getDefaultShippingMethod: state => state.shippingMethods.find(item => item.default)
}
Example #11
Source File: getters.ts From vue-storefront-1 with MIT License | 6 votes |
getters: GetterTree<TaxState, RootState> = {
getRules: (state) => state.rules,
getUserTaxGroupId: (state, getters, rootState) => {
if (!getters.getIsUserGroupedTaxActive) return
const storeViewTax = rootState.storeView.tax
const currentUser = rootState.user.current
if (storeViewTax.useOnlyDefaultUserGroupId || !currentUser) {
return storeViewTax.userGroupId
}
return currentUser.group_id
},
getIsUserGroupedTaxActive: (state, getters, rootState) => {
return typeof currentStoreView().tax.userGroupId === 'number'
}
}
Example #12
Source File: getters.ts From vue-storefront-1 with MIT License | 6 votes |
getters: GetterTree<ProductState, RootState> = {
getCurrentProduct: state => state.current,
getCurrentProductConfiguration: state => state.current_configuration,
getCurrentProductOptions: state => state.current_options,
getOriginalProduct: (state, getters) => {
if (!getters.getCurrentProduct) return null
return state.original || {
...getters.getCurrentProduct,
id: getters.getCurrentProduct.parentId || getters.getCurrentProduct.id
}
},
getParentProduct: state => state.parent,
getProductsSearchResult: state => state.list,
getProducts: (state, getters) => getters.getProductsSearchResult.items,
getProductGallery: state => state.productGallery,
getProductRelated: state => state.related,
getCurrentCustomOptions: state => state.current_custom_options
}
Example #13
Source File: getters.ts From vue3-cesium-typescript-start-up-template with MIT License | 5 votes |
getters: GetterTree<State, RootState> = {
// getTestStr: (state) => state.test.toString() + 'str',
}
Example #14
Source File: getters.ts From vue3-cesium-typescript-start-up-template with MIT License | 5 votes |
getters: GetterTree<OtherState, RootState> = {
// getTestStr: (state) => state.test.toString() + 'str',
}
Example #15
Source File: getters.ts From vue-storefront-1 with MIT License | 5 votes |
getters: GetterTree<CompareState, RootState> = {
isEmpty: state => state.items.length === 0,
isOnCompare: state => product => state.items.some(p => p.sku === product.sku),
isCompareLoaded: state => state.loaded,
getCompareProductsCount: state => state.items.length,
getCompareItems: state => state.items
}
Example #16
Source File: getters.ts From vue-storefront-1 with MIT License | 5 votes |
getters: GetterTree<OrderState, RootState> = {
getSessionOrderHashes: state => state.session_order_hashes
}
Example #17
Source File: getters.ts From vue-storefront-1 with MIT License | 5 votes |
getters: GetterTree<WishlistState, RootState> = {
isOnWishlist: state => product =>
state.items.some(p => p.sku === product.sku),
isWishlistLoaded: state => state.loaded,
getWishlistItemsCount: state => state.items.length
}
Example #18
Source File: getters.ts From vue-storefront-1 with MIT License | 5 votes |
getters: GetterTree<RootState, RootState> = {
getCurrentStoreView: state => state.storeView
}
Example #19
Source File: getters.ts From vue3-cesium-typescript-start-up-template with MIT License | 5 votes |
getters: GetterTree<Tool3DTileState, RootState> = {
// getTestStr: (state) => state.test.toString() + 'str',
}
Example #20
Source File: influences.ts From Corsace with MIT License | 5 votes |
getters: GetterTree<InfluenceState, RootState> = { }
Example #21
Source File: getters.ts From vue3-cesium-typescript-start-up-template with MIT License | 5 votes |
getters: GetterTree<MeasureState, RootState> = {
// getTestStr: (state) => state.test.toString() + 'str',
}
Example #22
Source File: getters.ts From vue3-cesium-typescript-start-up-template with MIT License | 5 votes |
getters: GetterTree<ImageryState, RootState> = {
// getTestStr: (state) => state.test.toString() + 'str',
}
Example #23
Source File: getters.ts From vue3-cesium-typescript-start-up-template with MIT License | 5 votes |
getters: GetterTree<DrawState, RootState> = {
// getTestStr: (state) => state.test.toString() + 'str',
}
Example #24
Source File: getters.ts From vue3-cesium-typescript-start-up-template with MIT License | 5 votes |
getters: GetterTree<State, RootState> & Getter = {
[LocationBarGetterTypes.ALL_SHOW](state) {
return state.showCameraLocation || state.showFPS || state.showMouseLocation
},
}
Example #25
Source File: getters.ts From vue3-cesium-typescript-start-up-template with MIT License | 5 votes |
getters: GetterTree<JTPrimitiveState, RootState> = {
// getTestStr: (state) => state.test.toString() + 'str',
}
Example #26
Source File: getters.ts From vue3-cesium-typescript-start-up-template with MIT License | 5 votes |
getters: GetterTree<State, RootState> = {}
Example #27
Source File: getters.ts From LiveAtlas with Apache License 2.0 | 5 votes |
getters: GetterTree<State, State> & Getters = {
playerMarkersEnabled(state: State): boolean {
return state.components.players.markers !== undefined;
},
markerUIEnabled(state: State): boolean {
return !state.ui.disableMarkerUI;
},
coordinatesControlEnabled(state: State): boolean {
return state.components.coordinatesControl !== undefined;
},
clockControlEnabled(state: State): boolean {
return state.components.clockControl !== undefined;
},
loginEnabled(state: State): boolean {
return state.components.login || state.loginRequired;
},
night(state: State): boolean {
return getMinecraftTime(state.currentWorldState.timeOfDay).night;
},
mapBackground(state: State): string {
if(!state.currentMap) {
return 'transparent';
}
if(state.currentMap.nightAndDay) {
if(getMinecraftTime(state.currentWorldState.timeOfDay).night) {
return state.currentMap.backgroundNight || state.currentMap.background || 'transparent';
}
return state.currentMap.backgroundDay || state.currentMap.background || 'transparent';
}
return state.currentMap.background || 'transparent';
},
url(state: State): string {
if(!state.currentWorld || !state.currentMap) {
return '';
}
return getUrlForLocation(state.currentMap, state.currentLocation, state.currentZoom);
},
pageTitle(state: State): string {
return state.configuration.title
.replace(/{world}/gi, state.currentWorld?.displayName || 'No world')
.replace(/{map}/gi, state.currentMap?.displayName || 'No map');
},
playersHeading(state: State): string {
return state.messages.playersHeading
.replace('{cur}', state.players.size.toString())
.replace('{max}', state.maxPlayers.toString());
}
}
Example #28
Source File: index.ts From vueconf-london with MIT License | 5 votes |
getters: GetterTree<State, State> = {
finishedTodos(state) {
return state.todos.filter((todo) => todo.isFinished)
},
unfinishedTodos(state) {
return state.todos.filter((todo) => !todo.isFinished)
},
filteredTodos(state, getters): Todo[] {
switch (state.filter) {
case "finished":
return getters.finishedTodos
case "unfinished":
return getters.unfinishedTodos
case "all":
return state.todos
}
},
}
Example #29
Source File: index.ts From Corsace with MIT License | 5 votes |
getters: GetterTree<RootState, RootState> = { }