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

Feature - async/await support #2092

Merged
merged 3 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/build/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function setupDevServer (app, cb) {
let template

// modify client config to work with hot middleware
clientConfig.entry.app = ['webpack-hot-middleware/client', clientConfig.entry.app]
clientConfig.entry.app = ['webpack-hot-middleware/client', ...clientConfig.entry.app]
clientConfig.output.filename = '[name].js'
clientConfig.plugins.push(
new webpack.HotModuleReplacementPlugin(),
Expand Down
2 changes: 1 addition & 1 deletion core/build/webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = {
],
devtool: 'source-map',
entry: {
app: './core/client-entry.ts'
app: ['babel-polyfill', './core/client-entry.ts']
},
output: {
path: path.resolve(__dirname, '../../dist'),
Expand Down
2 changes: 1 addition & 1 deletion core/build/webpack.prod.sw.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const SWPrecachePlugin = require('sw-precache-webpack-plugin')
module.exports = merge(base, {
mode: 'production',
target: 'web',
entry: './core/service-worker/index.js',
entry: ['babel-polyfill', './core/service-worker/index.js'],
output: {
filename: 'core-service-worker.js'
},
Expand Down
2 changes: 1 addition & 1 deletion core/build/webpack.server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const VueSSRPlugin = require('vue-ssr-webpack-plugin')
module.exports = merge(base, {
mode: 'development',
target: 'node',
entry: './core/server-entry.ts',
entry: ['babel-polyfill', './core/server-entry.ts'],
output: {
filename: 'server-bundle.js',
libraryTarget: 'commonjs2'
Expand Down
20 changes: 9 additions & 11 deletions core/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ export default {
rootCategories: 'category/list'
})
},
asyncData ({ store, route, context }) { // this is for SSR purposes to prefetch data
return new Promise((resolve, reject) => {
if (context) context.output.cacheTags.add(`home`)
Logger.info('Calling asyncData in Home Page (core)')()
EventBus.$emitFilter('home-after-load', { store: store, route: route }).then((results) => {
return resolve()
}).catch((err) => {
console.error(err)
reject(err)
})
})
async asyncData ({ store, route, context }) { // this is for SSR purposes to prefetch data
if (context) context.output.cacheTags.add(`home`)
Logger.info('Calling asyncData in Home Page (core)')()
try {
await EventBus.$emitFilter('home-after-load', { store: store, route: route })
} catch (e) {
console.error(e)
throw e
}
},
beforeMount () {
this.$store.dispatch('category/reset')
Expand Down
1 change: 1 addition & 0 deletions core/scripts/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require('babel-register')({
presets: [ 'env' ]
})
require('babel-polyfill')

module.exports = require('./server.js')
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.6",
"babel-loader": "^7.1.3",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.x",
"babel-preset-stage-2": "^6.13.0",
"case-sensitive-paths-webpack-plugin": "^2.1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,17 @@ export default {
}
}
},
beforeMount () {
async beforeMount () {
let inspirationsQuery = prepareQuery({queryConfig: 'inspirations'})

this.$store.dispatch('product/list', {
const res = await this.$store.dispatch('product/list', {
query: inspirationsQuery,
size: 12,
sort: 'created_at:desc'
}).then(res => {
if (res) {
this.products = res.items
}
})
if (res) {
this.products = res.items
}
},
components: {
ProductsSlider
Expand Down
73 changes: 30 additions & 43 deletions src/themes/default/pages/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,57 +72,44 @@ export default {
// Load personal and shipping details for Checkout page from IndexedDB
this.$store.dispatch('checkout/load')
},
beforeMount () {
async beforeMount () {
if (this.$store.state.__DEMO_MODE__) {
this.$store.dispatch('claims/check', { claimCode: 'onboardingAccepted' }).then((onboardingClaim) => {
if (!onboardingClaim) { // show onboarding info
this.$bus.$emit('modal-toggle', 'modal-onboard')
this.$store.dispatch('claims/set', { claimCode: 'onboardingAccepted', value: true })
}
})
const onboardingClaim = await this.$store.dispatch('claims/check', { claimCode: 'onboardingAccepted' })
if (!onboardingClaim) { // show onboarding info
this.$bus.$emit('modal-toggle', 'modal-onboard')
this.$store.dispatch('claims/set', { claimCode: 'onboardingAccepted', value: true })
}
}
},
asyncData ({ store, route }) { // this is for SSR purposes to prefetch data
async asyncData ({ store, route }) { // this is for SSR purposes to prefetch data
const config = store.state.config
return new Promise((resolve, reject) => {
Logger.info('Calling asyncData in Home (theme)')()

let newProductsQuery = prepareQuery({ queryConfig: 'newProducts' })
let coolBagsQuery = prepareQuery({ queryConfig: 'coolBags' })
Logger.info('Calling asyncData in Home (theme)')()

store.dispatch('category/list', { includeFields: config.entities.optimize ? config.entities.category.includeFields : null }).then((categories) => {
store.dispatch('product/list', {
query: newProductsQuery,
size: 8,
sort: 'created_at:desc',
includeFields: config.entities.optimize ? (config.products.setFirstVarianAsDefaultInURL ? config.entities.productListWithChildren.includeFields : config.entities.productList.includeFields) : []
}).catch(err => {
reject(err)
}).then((res) => {
if (res) {
store.state.homepage.new_collection = res.items
}
let newProductsQuery = prepareQuery({ queryConfig: 'newProducts' })
let coolBagsQuery = prepareQuery({ queryConfig: 'coolBags' })

store.dispatch('product/list', {
query: coolBagsQuery,
size: 4,
sort: 'created_at:desc',
includeFields: config.entities.optimize ? (config.products.setFirstVarianAsDefaultInURL ? config.entities.productListWithChildren.includeFields : config.entities.productList.includeFields) : []
}).then((res) => {
if (res) {
store.state.homepage.coolbags_collection = res.items
}
return resolve()
}).catch(err => {
reject(err)
})
}).catch(err => {
reject(err)
})
}).catch(err => {
reject(err)
})
await store.dispatch('category/list', { includeFields: config.entities.optimize ? config.entities.category.includeFields : null })

const newProductsResult = await store.dispatch('product/list', {
query: newProductsQuery,
size: 8,
sort: 'created_at:desc',
includeFields: config.entities.optimize ? (config.products.setFirstVarianAsDefaultInURL ? config.entities.productListWithChildren.includeFields : config.entities.productList.includeFields) : []
})
if (newProductsResult) {
store.state.homepage.new_collection = newProductsResult.items
}

const coolBagsResult = await store.dispatch('product/list', {
query: coolBagsQuery,
size: 4,
sort: 'created_at:desc',
includeFields: config.entities.optimize ? (config.products.setFirstVarianAsDefaultInURL ? config.entities.productListWithChildren.includeFields : config.entities.productList.includeFields) : []
})
if (coolBagsResult) {
store.state.homepage.coolbags_collection = coolBagsResult.items
}
}
}
</script>
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,15 @@ babel-plugin-transform-vue-jsx@^4.0.1:
dependencies:
esutils "^2.0.2"

babel-polyfill@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153"
integrity sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=
dependencies:
babel-runtime "^6.26.0"
core-js "^2.5.0"
regenerator-runtime "^0.10.5"

babel-preset-env@^1.6.x:
version "1.7.0"
resolved "https://registry.yarnpkg.com/babel-preset-env/-/babel-preset-env-1.7.0.tgz#dea79fa4ebeb883cd35dab07e260c1c9c04df77a"
Expand Down Expand Up @@ -8610,6 +8619,11 @@ regenerate@^1.2.1, regenerate@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"

regenerator-runtime@^0.10.5:
version "0.10.5"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658"
integrity sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=

regenerator-runtime@^0.11.0, regenerator-runtime@^0.11.1:
version "0.11.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"
Expand Down