-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(atomic): split the atomic store into composable parts (#4806)
https://coveord.atlassian.net/browse/KIT-3814 The atomic store was messy. The common store was way too big. There was no need for all that stuff in every store.
- Loading branch information
1 parent
e3801cc
commit de2a920
Showing
29 changed files
with
444 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 28 additions & 30 deletions
58
packages/atomic/src/components/commerce/atomic-commerce-recommendation-interface/store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,43 @@ | ||
import {ChildProduct} from '@coveo/headless/commerce'; | ||
import {DEFAULT_MOBILE_BREAKPOINT} from '../../../utils/replace-breakpoint'; | ||
import { | ||
AtomicCommonStore, | ||
AtomicCommonStoreData, | ||
createAtomicCommonStore, | ||
BaseStore, | ||
createBaseStore, | ||
ResultListInfo, | ||
setLoadingFlag, | ||
unsetLoadingFlag, | ||
} from '../../common/interface/store'; | ||
import {makeDesktopQuery} from '../atomic-commerce-layout/commerce-layout'; | ||
|
||
export interface AtomicStoreData extends AtomicCommonStoreData { | ||
mobileBreakpoint: string; | ||
currentQuickviewPosition: number; | ||
activeProductChild: ChildProduct | undefined; | ||
interface Data { | ||
loadingFlags: string[]; | ||
iconAssetsPath: string; | ||
resultList: ResultListInfo | undefined; | ||
} | ||
|
||
export interface AtomicCommerceRecommendationStore | ||
extends AtomicCommonStore<AtomicStoreData> { | ||
isMobile(): boolean; | ||
} | ||
export type CommerceRecommendationStore = BaseStore<Data> & { | ||
isAppLoaded(): boolean; | ||
unsetLoadingFlag(loadingFlag: string): void; | ||
setLoadingFlag(flag: string): void; | ||
}; | ||
|
||
export function createAtomicCommerceRecommendationStore(): AtomicCommerceRecommendationStore { | ||
const commonStore = createAtomicCommonStore<AtomicStoreData>({ | ||
export function createCommerceRecommendationStore(): CommerceRecommendationStore { | ||
const store = createBaseStore<Data>({ | ||
loadingFlags: [], | ||
facets: {}, | ||
numericFacets: {}, | ||
dateFacets: {}, | ||
categoryFacets: {}, | ||
facetElements: [], | ||
iconAssetsPath: '', | ||
mobileBreakpoint: DEFAULT_MOBILE_BREAKPOINT, | ||
fieldsToInclude: [], | ||
currentQuickviewPosition: -1, | ||
activeProductChild: undefined, | ||
resultList: undefined, | ||
}); | ||
|
||
return { | ||
...commonStore, | ||
...store, | ||
|
||
isAppLoaded() { | ||
return !store.state.loadingFlags.length; | ||
}, | ||
|
||
unsetLoadingFlag(loadingFlag: string) { | ||
unsetLoadingFlag(store, loadingFlag); | ||
}, | ||
|
||
isMobile() { | ||
return !window.matchMedia( | ||
makeDesktopQuery(commonStore.state.mobileBreakpoint) | ||
).matches; | ||
setLoadingFlag(loadingFlag: string) { | ||
setLoadingFlag(store, loadingFlag); | ||
}, | ||
}; | ||
} |
Oops, something went wrong.