Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Improved: code to use a getter to get the filter aggregations(#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Jan 11, 2021
1 parent 406c7f0 commit c3bbad2
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions pages/Category.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ import {
const THEME_PAGE_SIZE = 12;
const LAZY_LOADING_ACTIVATION_BREAKPOINT = 1024;
var unsubscribeFromStoreAction = ''
var aggs = ''
const composeInitialPageState = async (store, route, forceLoad = false) => {
try {
Expand Down Expand Up @@ -284,9 +282,7 @@ export default {
currentPage: 1,
getMoreCategoryProducts: [],
browserWidth: 0,
isFilterSidebarOpen: false,
unsubscribeFromStoreAction: null,
aggregations: null
isFilterSidebarOpen: false
};
},
computed: {
Expand All @@ -298,6 +294,7 @@ export default {
getAvailableFilters: 'category-next/getAvailableFilters',
getCurrentFilters: 'category-next/getCurrentFilters',
getSystemFilterNames: 'category-next/getSystemFilterNames',
getAggregations: 'category-next/getAggregations',
getCategories: 'category/getCategories',
getBreadcrumbsRoutes: 'breadcrumbs/getBreadcrumbsRoutes',
getBreadcrumbsCurrent: 'breadcrumbs/getBreadcrumbsCurrent'
Expand Down Expand Up @@ -391,7 +388,7 @@ export default {
.reduce((result, [filterType, filters]) => {
result[`${filterType}_filter`] = filters.map(filter => ({
...filter,
count: this.getFilterCount(filter) || '',
count: this.getFilterCount(filter) || '0',
color:
filterType === 'color'
? (config.products.colorMappings &&
Expand Down Expand Up @@ -436,11 +433,6 @@ export default {
async asyncData ({ store, route, context }) {
// this is for SSR purposes to prefetch data - and it's always executed before parent component methods
if (context) context.output.cacheTags.add('category')
unsubscribeFromStoreAction = store.subscribeAction(action => {
if (action.type === 'category-next/loadAvailableFiltersFrom') {
aggs = action.payload.aggregations;
}
});
await composeInitialPageState(store, route);
},
async beforeRouteEnter (to, from, next) {
Expand Down Expand Up @@ -469,7 +461,6 @@ export default {
this.getBrowserWidth();
},
beforeDestroy () {
unsubscribeFromStoreAction();
this.$bus.$off('product-after-list', this.initPagination);
window.removeEventListener('resize', this.getBrowserWidth);
},
Expand Down Expand Up @@ -550,9 +541,9 @@ export default {
return aggregations
.reduce((result, aggregation) => {
const bucket =
aggs &&
aggs[aggregation] &&
aggs[aggregation].buckets.find(
this.getAggregations &&
this.getAggregations[aggregation] &&
this.getAggregations[aggregation].buckets.find(
bucket => String(bucket.key) === String(filter.id)
);
Expand Down

0 comments on commit c3bbad2

Please sign in to comment.