diff --git a/core/lib/module.ts b/core/lib/module.ts index 25666a11d4..f1a0a3dbfd 100644 --- a/core/lib/module.ts +++ b/core/lib/module.ts @@ -32,6 +32,10 @@ export class VueStorefrontModule { return this._c } + public set config (config) { + this._c = config + } + private static _registeredModules: VueStorefrontModuleConfig[] = [] private static _doesStoreAlreadyExists (key: string) : boolean { @@ -60,8 +64,9 @@ export class VueStorefrontModule { private _extend (extendedConfig: VueStorefrontModule) { const key = this._c.key - this._c = merge(this._c, extendedConfig.config) + this._c = merge(this._c, extendedConfig) Logger.info('Module "' + key + '" has been succesfully extended.', 'module')() + debugger; } public register (): VueStorefrontModuleConfig | void { diff --git a/src/modules/index.ts b/src/modules/index.ts index 7e5d3fbef3..7709468d6f 100644 --- a/src/modules/index.ts +++ b/src/modules/index.ts @@ -21,20 +21,30 @@ import { PaymentCashOnDelivery } from './payment-cash-on-delivery'; import { RawOutputExample } from './raw-output-example' import { Magento2CMS } from './magento-2-cms' -// Some modules that still needs API refactoring are temporary registered in core -// This is how you can adjust any module with application-specific behavior -// const extendedExample = { -// key: 'example', -// afterRegistration: function(isServer, config) { -// console.info('Hello, im extended now!') + +// This is how you can extend any of VS modues +// const extendCartVuex = { +// actions: { +// load () { +// console.info('New load function') +// } // } -// } +// } -// extendModule(extendedExample) +// const cartExtend = { +// key: 'cart', +// afterRegistration: function(isServer, config) { +// console.info('New afterRegistration hook') +// }, +// store: { modules: [{ key: 'cart', module: extendCartVuex }] }, +// } + +// extendModule(cartExtend) /** * Some of the modules are registered lazily only when components from module are appearing on current page. * If you want to use this modules in pages without it's components you need to remember about registering module first + * In VS 1.8 this modules will be semlessly lazyLoaded after proper action dispatch * - Wishlist */ export const registerModules: VueStorefrontModule[] = [ diff --git a/src/modules/module-template/index.ts b/src/modules/module-template/index.ts index 4c78752d01..2c53165f6e 100644 --- a/src/modules/module-template/index.ts +++ b/src/modules/module-template/index.ts @@ -17,7 +17,7 @@ export const cacheStorage = initCacheStorage(KEY) // Put everything that should extend the base app here so it can be later registered as VS module const moduleConfig: VueStorefrontModuleConfig = { key: KEY, - store: { modules: [{ key: KEY, module }, { key: 'mailchimp', module: extendMailchimp }], plugin }, + store: { modules: [{ key: KEY, module }], plugin }, beforeRegistration, afterRegistration, router: { beforeEach, afterEach } diff --git a/src/modules/module-template/store/mailchimp/index.ts b/src/modules/module-template/store/mailchimp/index.ts deleted file mode 100644 index 024d9be6c0..0000000000 --- a/src/modules/module-template/store/mailchimp/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -// With store.extend property you can extend currently existing VS modules. -// Vuex Module below will be merged with the one with the same key property. -// You can add new properties to currently existing stores or override existing ones just by using the same name -// In this example we will override mailchimp vuex store -import { Module } from 'vuex' - -// you can use mailchimp state instead of any -export const extendMailchimp: Module = { - state: { - addedproperty: 'Hello!' - }, - actions: { - unsubscribe () { - // mailchimp module 'unsubscribe' action will be overwritten by this one - console.info('Hello from mailchimp module extension! Now this action is broken ;o') - }, - logHello () { - // this action will be added to mailchimp vuex module - console.info('Hello!') - } - } -} \ No newline at end of file