Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules 2.0 #3152

Merged
merged 73 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c8bd255
init package, create modules api, setup lerna
filrak Jun 27, 2019
39fe17e
rename hooks convention naming to listener/executor
filrak Jun 27, 2019
bac301a
module-next template
filrak Jun 27, 2019
142eda5
update extendStore signature
filrak Jun 27, 2019
effad59
after merge
filrak Jun 27, 2019
f45c3a1
update extendStore
filrak Jun 27, 2019
45f4691
update exports
filrak Jun 27, 2019
4cdaa48
before/after hooks naming convention
filrak Jun 27, 2019
947f362
add optional argument to listener function
filrak Jun 27, 2019
91fd1c9
add afterPlaceOrder Hook
filrak Jun 27, 2019
5fb4315
add depreciation notes
filrak Jun 27, 2019
cd37d38
init boilerplate and prep build scripts
filrak Jul 1, 2019
4b8cb33
remove autogenerated files
filrak Jul 2, 2019
3f2be04
make generated js ignored
filrak Jul 2, 2019
a414803
update helpers
filrak Jul 2, 2019
e52b1e9
change lerna versining to independent
filrak Jul 2, 2019
716377f
add unit tests
filrak Jul 2, 2019
016bec9
comment unit tests for now
filrak Jul 2, 2019
1e4b05e
module typings
filrak Jul 2, 2019
970bf7f
remove demo module
filrak Jul 2, 2019
36a24df
remove boilerplates from packages
filrak Jul 2, 2019
eeef1bf
add commands to cli
filrak Jul 2, 2019
b201e73
cli-generator for module boilerplates
filrak Jul 4, 2019
a7a8631
update manual for vsf cli
filrak Jul 4, 2019
1e4d123
Depreciacion note for old modules
filrak Jul 8, 2019
4ad323a
rewrite cart to new format
filrak Jul 8, 2019
99b14a8
catalog module rewritten
filrak Jul 8, 2019
8d559d1
catalog module rewrite to new format
filrak Jul 8, 2019
2950468
fix typo
filrak Jul 8, 2019
e69716c
remove unnecessar afterAppInit
filrak Jul 8, 2019
4e01d62
afterappInit removed from checkoutmodule
filrak Jul 8, 2019
938f30e
correct appConfig ref
filrak Jul 8, 2019
b8ea14d
lint fix
filrak Jul 8, 2019
d6e1c38
add module package build to ci
filrak Jul 8, 2019
a99db39
correct package name for moduel in build process
filrak Jul 8, 2019
0df6fc0
update build process
filrak Jul 8, 2019
d0289e9
typings for hooks
filrak Jul 8, 2019
82cc40b
typings for hooks
filrak Jul 8, 2019
d983a57
merge conflicts, update registerModule for duplicated registrations
filrak Jul 9, 2019
90b26b1
typed module
filrak Jul 9, 2019
be9582e
add extendStore function
Jul 9, 2019
05e86a1
Merge branch 'develop' into modules-2.0
Jul 9, 2019
fea8f00
Merge pull request #1 from przspa/pull/3152
filrak Jul 9, 2019
474d102
fix multistore
filrak Jul 9, 2019
d72493a
Merge branch 'modules-2.0' of https://github.com/filrak/vue-storefron…
filrak Jul 9, 2019
0a5e0f4
better typings
filrak Jul 9, 2019
ded109a
proper moduel npm packe and preparation for per-module hooks
filrak Jul 10, 2019
0c7d9dc
update signatures
filrak Jul 10, 2019
9655b4e
after conflicts res
filrak Jul 10, 2019
3f4462f
update modules to use StorageManager
filrak Jul 10, 2019
7c53b70
hooks distributed across modules
filrak Jul 10, 2019
c064b29
exlint fix
filrak Jul 10, 2019
3551b2b
add descriptions for storeView
filrak Jul 10, 2019
e788ebd
typo fix ;)
filrak Jul 10, 2019
4288063
typo fix ;)
filrak Jul 10, 2019
9566a0b
remove vsf-g
filrak Jul 11, 2019
bed55fe
Update core/modules-entry.ts
filrak Jul 11, 2019
c86045f
Update core/lib/module/index.ts
filrak Jul 11, 2019
dbfe6ed
Update core/app.ts
filrak Jul 11, 2019
e12f0c3
Update core/app.ts
filrak Jul 11, 2019
cebe3d3
Update core/mixins/composite.js
filrak Jul 11, 2019
bbaa910
remove tests, fix for StorageManager
filrak Jul 11, 2019
c0d64f1
Merge branch 'modules-2.0' of https://github.com/filrak/vue-storefron…
filrak Jul 11, 2019
338cf3f
Merge branch 'develop' into modules-2.0
patzick Jul 12, 2019
e4247b7
Merge branch 'develop' into modules-2.0
pkarw Jul 12, 2019
dad7b61
Merge branch 'develop' into modules-2.0
pkarw Jul 12, 2019
63ce1a6
fix correct boilerplate and unit test
filrak Jul 14, 2019
b8fcaf5
Merge remote-tracking branch 'main/develop' into modules-2.0
filrak Jul 14, 2019
e004f94
transpile packages files
filrak Jul 14, 2019
a60b245
Merge branch 'modules-2.0' of https://github.com/filrak/vue-storefron…
filrak Jul 14, 2019
83ff79c
restore tsconfig and remove build step for modules
filrak Jul 14, 2019
032cd7c
hide module webpack config
filrak Jul 14, 2019
67ca32c
hide module build config inside @vue-storefront/module
filrak Jul 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
@@ -1,2 +1,3 @@
core/build/*.js
node_modules
packages/module/*.js
12 changes: 10 additions & 2 deletions core/app.ts
Expand Up @@ -31,11 +31,15 @@ import store from '@vue-storefront/core/store'

import { enabledModules } from './modules-entry'

// Will be deprecated in 1.8
// Will be deprecated in 2.0
import { registerExtensions } from '@vue-storefront/core/compatibility/lib/extensions'
import { registerExtensions as extensions } from 'src/extensions'
import globalConfig from 'config'

import { injectReferences } from '@vue-storefront/module'
import { coreHooksExecutors } from '@vue-storefront/core/hooks'
import { registerNewModules } from 'src/modules';

function createRouter (): VueRouter {
return new VueRouter({
mode: 'history',
Expand Down Expand Up @@ -75,7 +79,7 @@ const createApp = async (ssrContext, config, storeCode = null): Promise<{app: Vu
store.state.storeView = storeView
// store.state.shipping.methods = shippingMethods

// to depreciate in near future
// @deprecated from 2.0
once('__VUE_EXTEND__', () => {
Vue.use(Vuelidate)
Vue.use(VueLazyload, {attempt: 2, preLoad: 1.5})
Expand Down Expand Up @@ -112,10 +116,14 @@ const createApp = async (ssrContext, config, storeCode = null): Promise<{app: Vu
ssrContext
}

injectReferences(app, store, router, globalConfig)
registerNewModules()
registerModules(enabledModules, appContext)
registerExtensions(extensions, app, router, store, config, ssrContext)
registerTheme(globalConfig.theme, app, router, store, globalConfig, ssrContext)

coreHooksExecutors.afterAppInit()
// @deprecated from 2.0
EventBus.$emit('application-after-init', app)

return { app, router, store }
Expand Down
41 changes: 41 additions & 0 deletions core/hooks.ts
@@ -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
}
2 changes: 2 additions & 0 deletions core/lib/module/index.ts
@@ -1,3 +1,4 @@
// @deprecated from 2.0
import { Module } from 'vuex'
import { RouteConfig, NavigationGuard } from 'vue-router'
import Vue from 'vue'
Expand Down Expand Up @@ -77,6 +78,7 @@ class VueStorefrontModule {

public register (): VueStorefrontModuleConfig | void {
if (!this._isRegistered) {
Logger.warn('The module you are registering is using outdated API that will soon be depreciated. Please check https://docs.vuestorefront.io to learn more.', 'module', this._c.key)()
let areStoresUnique = true
const VSF: VSF = {
Vue,
Expand Down
4 changes: 3 additions & 1 deletion core/lib/multistore.ts
Expand Up @@ -8,6 +8,7 @@ import merge from 'lodash-es/merge'
import { RouterManager } from '@vue-storefront/core/lib/router-manager'
import VueRouter, { RouteConfig, RawLocation } from 'vue-router'
import config from 'config'
import { coreHooksExecutors } from '@vue-storefront/core/hooks'
import { StorageManager } from '@vue-storefront/core/store/lib/storage-manager'

export interface LocalizedRoute {
Expand Down Expand Up @@ -97,13 +98,14 @@ export function prepareStoreView (storeCode: string): StoreView {
loadLanguageAsync(storeView.i18n.defaultLocale)

if (storeViewHasChanged) {
storeView = coreHooksExecutors.beforeStoreViewChange(storeView)
rootStore.state.storeView = storeView
}
if (storeViewHasChanged || StorageManager.currentStoreCode !== storeCode) {
initializeSyncTaskStorage()
StorageManager.currentStoreCode = storeView.storeCode
}

coreHooksExecutors.afterStoreViewChange(storeView)
return storeView
}

Expand Down
2 changes: 1 addition & 1 deletion core/mixins/composite.js
@@ -1,7 +1,7 @@
import EventBus from '@vue-storefront/core/compatibility/plugins/event-bus'
import { Logger } from '@vue-storefront/core/lib/logger'

// to be deprecated
// @deprecated from 2.0
export default {
beforeCreated () {
const eventName = this.$options.name.toLowerCase() + '-before-created'
Expand Down
2 changes: 2 additions & 0 deletions core/modules-entry.ts
Expand Up @@ -5,6 +5,8 @@ import { Order } from './modules/order'
import { User } from './modules/user'
import { registerModules } from 'src/modules'
import { Breadcrumbs } from './modules/breadcrumbs'

// @deprecated from 2.0, use registerModule instead
export const enabledModules: VueStorefrontModule[] = [
Breadcrumbs,
Cms,
Expand Down
7 changes: 0 additions & 7 deletions core/modules/cart/hooks/afterRegistration.ts

This file was deleted.

15 changes: 0 additions & 15 deletions core/modules/cart/hooks/beforeRegistration.ts

This file was deleted.

25 changes: 14 additions & 11 deletions core/modules/cart/index.ts
@@ -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))
}
2 changes: 1 addition & 1 deletion core/modules/cart/store/index.ts
Expand Up @@ -4,7 +4,7 @@ import getters from './getters'
import mutations from './mutations'
import CartState from '../types/CartState'

export const module: Module<CartState, any> = {
export const cartStore: Module<CartState, any> = {
namespaced: true,
state: {
isMicrocartOpen: false,
Expand Down
54 changes: 0 additions & 54 deletions core/modules/cart/test/unit/hooks/afterRegistration.spec.ts

This file was deleted.

67 changes: 0 additions & 67 deletions core/modules/cart/test/unit/hooks/beforeRegistration.spec.ts

This file was deleted.

27 changes: 0 additions & 27 deletions core/modules/catalog/hooks/beforeRegistration.ts

This file was deleted.