-
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 branch 'develop' into feature/#2773
- Loading branch information
Showing
53 changed files
with
637 additions
and
346 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
core/build/*.js | ||
node_modules | ||
packages/module/*.js |
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,41 @@ | ||
import { createListenerHook, createMutatorHook } from '@vue-storefront/module/hooks' | ||
|
||
const { hook: beforeStoreViewChangeHook, executor: beforeStoreViewChangeExecutor }: { | ||
hook: (storeViewMutator: (storeView: any) => any) => void, | ||
executor: any | ||
} = createMutatorHook() | ||
|
||
const { hook: afterStoreViewChangeHook, executor: afterStoreViewChangeExecutor }: { | ||
hook: (storeViewListener: (storeView?: any) => void) => void, | ||
executor: any | ||
} = createListenerHook() | ||
|
||
const { hook: afterAppInitHook, executor: afterAppInitExecutor }: { | ||
hook: (appInitListener: () => void) => void, | ||
executor: any | ||
} = createListenerHook() | ||
|
||
/** Only for internal usage in core */ | ||
const coreHooksExecutors = { | ||
afterAppInit: afterAppInitExecutor, | ||
beforeStoreViewChange: beforeStoreViewChangeExecutor, | ||
afterStoreViewChange: afterStoreViewChangeExecutor | ||
} | ||
|
||
const coreHooks = { | ||
/** Hook is fired right after whole application is initialized. Modules are registered and theme setted up */ | ||
afterAppInit: afterAppInitHook, | ||
/** Hook is fired directly before changing current storeView (multistrore) | ||
* @param storeView Inside this function you have access to order object that you can access and modify. It should return order object. | ||
*/ | ||
beforeStoreViewChange: beforeStoreViewChangeHook, | ||
/** Hook is fired right after storeView (multistore) is changed | ||
* @param storeView current storeView | ||
*/ | ||
afterStoreViewChange: afterStoreViewChangeHook | ||
} | ||
|
||
export { | ||
coreHooks, | ||
coreHooksExecutors | ||
} |
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,12 +1,15 @@ | ||
import { module } from './store' | ||
import { createModule } from '@vue-storefront/core/lib/module' | ||
import { beforeRegistration } from './hooks/beforeRegistration' | ||
import { afterRegistration } from './hooks/afterRegistration' | ||
import { StorefrontModule } from '@vue-storefront/module' | ||
import { cartStore } from './store' | ||
import { cartCacheHandlerFactory } from './helpers/cartCacheHandler'; | ||
import { isServer } from '@vue-storefront/core/helpers' | ||
import Vue from 'vue' | ||
import { initCacheStorage } from '@vue-storefront/core/helpers/initCacheStorage' | ||
|
||
export const KEY = 'cart' | ||
export const Cart = createModule({ | ||
key: KEY, | ||
store: { modules: [{ key: KEY, module }] }, | ||
beforeRegistration, | ||
afterRegistration | ||
}) | ||
export const CartModule: StorefrontModule = function (app, store, router, moduleConfig, appConfig) { | ||
initCacheStorage('carts') | ||
|
||
store.registerModule('cart', cartStore) | ||
|
||
if (!isServer) store.dispatch('cart/load') | ||
store.subscribe(cartCacheHandlerFactory(Vue)) | ||
} |
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
54 changes: 0 additions & 54 deletions
54
core/modules/cart/test/unit/hooks/afterRegistration.spec.ts
This file was deleted.
Oops, something went wrong.
67 changes: 0 additions & 67 deletions
67
core/modules/cart/test/unit/hooks/beforeRegistration.spec.ts
This file was deleted.
Oops, something went wrong.
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,12 +1,13 @@ | ||
import { Cart } from '../../index' | ||
import { CartModule } from '../../index' | ||
|
||
jest.mock('../../store', () => ({})); | ||
jest.mock('@vue-storefront/core/lib/module', () => ({ createModule: jest.fn(() => ({ module: 'cart' })) })); | ||
jest.mock('../../hooks/beforeRegistration', () => jest.fn()); | ||
jest.mock('../../hooks/afterRegistration', () => jest.fn()); | ||
jest.mock('@vue-storefront/module', () => ({ createModule: jest.fn(() => ({ module: 'cart' })) })); | ||
jest.mock('../../helpers/cartCacheHandler', () => ({ cartCacheHandlerFactory: jest.fn() })) | ||
jest.mock('@vue-storefront/core/helpers', () => ({ isServer: false })) | ||
jest.mock('@vue-storefront/core/helpers/initCacheStorage', () => ({ initCacheStorage: jest.fn() })); | ||
|
||
describe('Cart Module', () => { | ||
it('can be initialized', () => { | ||
expect(Cart).toBeTruthy() | ||
expect(CartModule).toBeTruthy() | ||
}) | ||
}); |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.