From df88b6d46d1ee90815d9fa96d8fb6b4743955821 Mon Sep 17 00:00:00 2001 From: sdras Date: Fri, 1 Dec 2017 17:23:52 -0700 Subject: [PATCH 1/4] simplify the getters where repetitive --- .nuxt/client.js | 99 ++ .nuxt/components/nuxt-error.vue | 22 + .nuxt/dist/LICENSES | 38 - .nuxt/dist/app.6c0e167f74d5671c0df8.js | 2 - .nuxt/dist/app.6c0e167f74d5671c0df8.js.map | 1 - .nuxt/dist/common.8128640c49a422d3e4b3.js | 3 - .nuxt/dist/common.8128640c49a422d3e4b3.js.map | 1 - .nuxt/dist/index.spa.html | 9 - .../layouts/default.b96ce676a48e8edd70cd.js | 2 - .../default.b96ce676a48e8edd70cd.js.map | 1 - .nuxt/dist/manifest.4ccfb9b79cced0a86787.js | 2 - .../dist/manifest.4ccfb9b79cced0a86787.js.map | 1 - .nuxt/dist/pages/cart.8ee4f9d335f58c37c289.js | 3 - .../pages/cart.8ee4f9d335f58c37c289.js.map | 1 - .../dist/pages/index.bc753ab75fa077f8731b.js | 2 - .../pages/index.bc753ab75fa077f8731b.js.map | 1 - .nuxt/dist/pages/men.b0d4fd0ef0d516183a92.js | 2 - .../pages/men.b0d4fd0ef0d516183a92.js.map | 1 - .nuxt/dist/pages/sale.bd5be994ecab3547b004.js | 2 - .../pages/sale.bd5be994ecab3547b004.js.map | 1 - .../dist/pages/women.af84e502a4ed238697c8.js | 2 - .../pages/women.af84e502a4ed238697c8.js.map | 1 - .nuxt/dist/vue-ssr-client-manifest.json | 976 ------------------ .nuxt/index.js | 2 +- .nuxt/server.js | 6 +- .nuxt/utils.js | 2 +- .nuxt/views/error.html | 2 +- store/index.js | 37 +- 28 files changed, 142 insertions(+), 1080 deletions(-) delete mode 100644 .nuxt/dist/LICENSES delete mode 100644 .nuxt/dist/app.6c0e167f74d5671c0df8.js delete mode 100644 .nuxt/dist/app.6c0e167f74d5671c0df8.js.map delete mode 100644 .nuxt/dist/common.8128640c49a422d3e4b3.js delete mode 100644 .nuxt/dist/common.8128640c49a422d3e4b3.js.map delete mode 100644 .nuxt/dist/index.spa.html delete mode 100644 .nuxt/dist/layouts/default.b96ce676a48e8edd70cd.js delete mode 100644 .nuxt/dist/layouts/default.b96ce676a48e8edd70cd.js.map delete mode 100644 .nuxt/dist/manifest.4ccfb9b79cced0a86787.js delete mode 100644 .nuxt/dist/manifest.4ccfb9b79cced0a86787.js.map delete mode 100644 .nuxt/dist/pages/cart.8ee4f9d335f58c37c289.js delete mode 100644 .nuxt/dist/pages/cart.8ee4f9d335f58c37c289.js.map delete mode 100644 .nuxt/dist/pages/index.bc753ab75fa077f8731b.js delete mode 100644 .nuxt/dist/pages/index.bc753ab75fa077f8731b.js.map delete mode 100644 .nuxt/dist/pages/men.b0d4fd0ef0d516183a92.js delete mode 100644 .nuxt/dist/pages/men.b0d4fd0ef0d516183a92.js.map delete mode 100644 .nuxt/dist/pages/sale.bd5be994ecab3547b004.js delete mode 100644 .nuxt/dist/pages/sale.bd5be994ecab3547b004.js.map delete mode 100644 .nuxt/dist/pages/women.af84e502a4ed238697c8.js delete mode 100644 .nuxt/dist/pages/women.af84e502a4ed238697c8.js.map delete mode 100644 .nuxt/dist/vue-ssr-client-manifest.json diff --git a/.nuxt/client.js b/.nuxt/client.js index bb6e34a..e8b7cbc 100644 --- a/.nuxt/client.js +++ b/.nuxt/client.js @@ -386,6 +386,9 @@ function fixPrepatch (to, ___) { this.setLayout(layout) + // Hot reloading + setTimeout(() => hotReloadAPI(this), 100) + }) } @@ -406,6 +409,99 @@ function nuxtReady (app) { } +// Special hot reload with asyncData(context) +function hotReloadAPI (_app) { + if (!module.hot) return + + let $components = [] + let $nuxt = _app.$nuxt + + while ($nuxt && $nuxt.$children && $nuxt.$children.length) { + $nuxt.$children.forEach((child, i) => { + if (child.$vnode.data.nuxtChild) { + let hasAlready = false + $components.forEach(component => { + if (component.$options.__file === child.$options.__file) { + hasAlready = true + } + }) + if (!hasAlready) { + $components.push(child) + } + } + $nuxt = child + }) + } + + $components.forEach(addHotReload.bind(_app)) +} + +function addHotReload ($component, depth) { + if ($component.$vnode.data._hasHotReload) return + $component.$vnode.data._hasHotReload = true + + var _forceUpdate = $component.$forceUpdate.bind($component.$parent) + + $component.$vnode.context.$forceUpdate = () => { + let Components = getMatchedComponents(router.currentRoute) + let Component = Components[depth] + if (!Component) return _forceUpdate() + if (typeof Component === 'object' && !Component.options) { + // Updated via vue-router resolveAsyncComponents() + Component = Vue.extend(Component) + Component._Ctor = Component + } + this.error() + let promises = [] + const next = function (path) { + this.$loading.finish && this.$loading.finish() + router.push(path) + } + let context = getContext({ route: router.currentRoute, store, isClient: true, isHMR: true, next: next.bind(this), error: this.error }, app) + this.$loading.start && this.$loading.start() + callMiddleware.call(this, Components, context) + .then(() => { + // If layout changed + if (depth !== 0) return Promise.resolve() + let layout = Component.options.layout || 'default' + if (typeof layout === 'function') { + layout = layout(context) + } + if (this.layoutName === layout) return Promise.resolve() + let promise = this.loadLayout(layout) + promise.then(() => { + this.setLayout(layout) + Vue.nextTick(() => hotReloadAPI(this)) + }) + return promise + }) + .then(() => { + return callMiddleware.call(this, Components, context, this.layout) + }) + .then(() => { + // Call asyncData(context) + let pAsyncData = promisify(Component.options.asyncData || noopData, context) + pAsyncData.then((asyncDataResult) => { + applyAsyncData(Component, asyncDataResult) + this.$loading.increase && this.$loading.increase(30) + }) + promises.push(pAsyncData) + // Call fetch() + Component.options.fetch = Component.options.fetch || noopFetch + let pFetch = Component.options.fetch(context) + if (!pFetch || (!(pFetch instanceof Promise) && (typeof pFetch.then !== 'function'))) { pFetch = Promise.resolve(pFetch) } + pFetch.then(() => this.$loading.increase && this.$loading.increase(30)) + promises.push(pFetch) + return Promise.all(promises) + }) + .then(() => { + this.$loading.finish && this.$loading.finish() + _forceUpdate() + setTimeout(() => hotReloadAPI(this), 100) + }) + } +} + async function mountApp(__app) { // Set global variables @@ -433,6 +529,9 @@ async function mountApp(__app) { // Call window.onNuxtReady callbacks nuxtReady(_app) + // Enable hot reloading + hotReloadAPI(_app) + }) } diff --git a/.nuxt/components/nuxt-error.vue b/.nuxt/components/nuxt-error.vue index f1b62c5..6384af3 100644 --- a/.nuxt/components/nuxt-error.vue +++ b/.nuxt/components/nuxt-error.vue @@ -8,6 +8,8 @@ Back to the home page

+

An error occurred while rendering the page. Check developer tools console for details.

+