-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2434 from filrak/module_factory
Module factory
- Loading branch information
Showing
33 changed files
with
219 additions
and
254 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { VueStorefrontModuleConfig } from './types' | ||
import { Module } from 'vuex' | ||
import merge from 'lodash-es/merge' | ||
import some from 'lodash-es/some' | ||
import find from 'lodash-es/find' | ||
|
||
function doesStoreAlreadyExists (key: string, registeredModules: VueStorefrontModuleConfig[]) : boolean { | ||
registeredModules.forEach(m => { | ||
if (m.store) { | ||
if (m.store.modules.some(m => m.key === key)) return true | ||
} | ||
}) | ||
return false | ||
} | ||
|
||
function mergeStores ( | ||
originalStore: { modules?: { key: string, module: Module<any, any> }[], plugin?: Function }, | ||
extendedStore: { modules?: { key: string, module: Module<any, any> }[], plugin?: Function } | ||
) { | ||
let mergedArray = [] | ||
originalStore.modules.map(item => { | ||
mergedArray.push(merge(item, find(extendedStore.modules, { 'key' : item.key }))); | ||
}) | ||
extendedStore.modules.map(extendedStoreItem => { | ||
if(some(originalStore.modules, null, { 'key' : extendedStoreItem.key}) === false){ | ||
mergedArray.push(extendedStoreItem) | ||
} | ||
}) | ||
return mergedArray | ||
} | ||
|
||
export { | ||
doesStoreAlreadyExists, | ||
mergeStores | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Module, Store } from 'vuex' | ||
import { RouteConfig, NavigationGuard } from 'vue-router' | ||
import { VueConstructor } from 'vue' | ||
import RootState from '@vue-storefront/core/types/RootState' | ||
|
||
interface VSF { | ||
Vue?: VueConstructor, | ||
config?: Object, | ||
store?: Store<RootState>, | ||
isServer?: boolean | ||
} | ||
|
||
interface VueStorefrontModuleConfig { | ||
key: string; | ||
store?: { modules?: { key: string, module: Module<any, any> }[], plugin?: Function }; | ||
router?: { routes?: RouteConfig[], beforeEach?: NavigationGuard, afterEach?: NavigationGuard }, | ||
beforeRegistration?: (VSF: VSF | VueConstructor, config?: Object, store?: Store<RootState>, isServer?: boolean) => void, | ||
afterRegistration?: (VSF: VSF | VueConstructor, config?: Object, store?: Store<RootState>, isServer?: boolean) => void, | ||
} | ||
|
||
export { | ||
VSF, | ||
VueStorefrontModuleConfig | ||
} |
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,13 +1,10 @@ | ||
import { module } from './store' | ||
import { VueStorefrontModule, VueStorefrontModuleConfig } from '@vue-storefront/core/lib/module' | ||
import { createModule } from '@vue-storefront/core/lib/module' | ||
|
||
export const KEY = 'breadcrumbs' | ||
|
||
const moduleConfig: VueStorefrontModuleConfig = { | ||
export const Breadcrumbs = createModule({ | ||
key: KEY, | ||
store: { modules: [ | ||
{ key: KEY, module: module } | ||
] }, | ||
} | ||
|
||
export const Breadcrumbs = new VueStorefrontModule(moduleConfig) | ||
}) |
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,15 +1,12 @@ | ||
import { module } from './store' | ||
import { VueStorefrontModule, VueStorefrontModuleConfig } from '@vue-storefront/core/lib/module' | ||
import { createModule } from '@vue-storefront/core/lib/module' | ||
import { beforeRegistration } from './hooks/beforeRegistration' | ||
import { afterRegistration } from './hooks/afterRegistration' | ||
|
||
export const KEY = 'cart' | ||
|
||
const moduleConfig: VueStorefrontModuleConfig = { | ||
export const Cart = createModule({ | ||
key: KEY, | ||
store: { modules: [{ key: KEY, module }] }, | ||
beforeRegistration, | ||
afterRegistration | ||
} | ||
|
||
export const Cart = new VueStorefrontModule(moduleConfig) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
import { cmsPageModule } from './store/page' | ||
import { cmsBlockModule } from './store/block' | ||
import { cmsHierarchyModule } from './store/hierarchy' | ||
import { VueStorefrontModule, VueStorefrontModuleConfig } from '@vue-storefront/core/lib/module' | ||
import { createModule } from '@vue-storefront/core/lib/module' | ||
import { beforeRegistration } from './hooks/beforeRegistration' | ||
import { plugin } from './store/plugin' | ||
import { initCacheStorage } from '@vue-storefront/core/helpers/initCacheStorage'; | ||
|
||
export const KEY = 'cms' | ||
export const cacheStorage = initCacheStorage(KEY) | ||
|
||
const moduleConfig: VueStorefrontModuleConfig = { | ||
export const Cms = createModule({ | ||
key: KEY, | ||
store: { modules: [ | ||
{ key: 'cmsPage', module: cmsPageModule }, | ||
{ key: 'cmsBlock', module: cmsBlockModule }, | ||
{ key: 'cmsHierarchy', module: cmsHierarchyModule } | ||
], plugin }, | ||
beforeRegistration | ||
} | ||
|
||
export const Cms = new VueStorefrontModule(moduleConfig) | ||
}) |
Oops, something went wrong.