From 3415caf9ed0cb86162c4a03b74d8d41e2fc63f7f Mon Sep 17 00:00:00 2001 From: Kamen Bundev Date: Wed, 1 Aug 2018 15:52:58 +0300 Subject: [PATCH 1/5] add: possibility to pass external history through mode expose: History and AbstractHistory --- build/configs.js | 3 +++ src/index.js | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/build/configs.js b/build/configs.js index f81ec3a93..685a64846 100644 --- a/build/configs.js +++ b/build/configs.js @@ -55,6 +55,9 @@ function genConfig (opts) { format: opts.format, banner, name: 'VueRouter' + }, + watch: { + chokidar: false } } diff --git a/src/index.js b/src/index.js index a1a7b8507..6ed23599f 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,10 @@ import { AbstractHistory } from './history/abstract' import type { Matcher } from './create-matcher' +export { History } from './history/base' + +export { AbstractHistory } + export default class VueRouter { static install: () => void; static version: string; @@ -62,6 +66,12 @@ export default class VueRouter { this.history = new AbstractHistory(this, options.base) break default: + if (mode && mode.constructor === Object) { + this.history = new mode.History(this, options.base) + mode = mode.name + break + } + if (process.env.NODE_ENV !== 'production') { assert(false, `invalid mode: ${mode}`) } From 6fff8a39989616563983a7015207dda2144b26a6 Mon Sep 17 00:00:00 2001 From: Kamen Bundev Date: Thu, 2 Aug 2018 15:14:13 +0300 Subject: [PATCH 2/5] fix: how external modes are initialized --- src/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 6ed23599f..db2b32da7 100644 --- a/src/index.js +++ b/src/index.js @@ -45,12 +45,19 @@ export default class VueRouter { this.afterHooks = [] this.matcher = createMatcher(options.routes || [], this) + let CustomHistory let mode = options.mode || 'hash' this.fallback = mode === 'history' && !supportsPushState && options.fallback !== false if (this.fallback) { mode = 'hash' } - if (!inBrowser) { + + if (mode && mode.constructor === Object) { + CustomHistory = mode.History + mode = mode.name + } + + if (!inBrowser && !CustomHistory) { mode = 'abstract' } this.mode = mode @@ -66,9 +73,8 @@ export default class VueRouter { this.history = new AbstractHistory(this, options.base) break default: - if (mode && mode.constructor === Object) { - this.history = new mode.History(this, options.base) - mode = mode.name + if (CustomHistory) { + this.history = new CustomHistory(this, options.base) break } From 16c66a90e2e6b20e87bee1c8de9d4227729f1017 Mon Sep 17 00:00:00 2001 From: Bundyo Date: Sat, 4 Aug 2018 09:40:30 +0300 Subject: [PATCH 3/5] fix: better plugin through mixins --- src/index.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index db2b32da7..b959d1b4a 100644 --- a/src/index.js +++ b/src/index.js @@ -45,7 +45,6 @@ export default class VueRouter { this.afterHooks = [] this.matcher = createMatcher(options.routes || [], this) - let CustomHistory let mode = options.mode || 'hash' this.fallback = mode === 'history' && !supportsPushState && options.fallback !== false if (this.fallback) { @@ -53,7 +52,20 @@ export default class VueRouter { } if (mode && mode.constructor === Object) { - CustomHistory = mode.History + class CustomHistory extends AbstractHistory { + constructor (router, base) { + super(router, base) + + this.init(router, base) + } + + callMethod(name, ...args) { + super[name](...args) + } + } + + Object.assign(CustomHistory.prototype, mode) + mode = mode.name } From ea5e54048032ef8f138278632710f8cbef465f13 Mon Sep 17 00:00:00 2001 From: Kamen Bundev Date: Mon, 6 Aug 2018 11:42:03 +0300 Subject: [PATCH 4/5] fix: use a simpler factory mixin for the extensibility point --- src/index.js | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/index.js b/src/index.js index b959d1b4a..4147851bf 100644 --- a/src/index.js +++ b/src/index.js @@ -15,10 +15,6 @@ import { AbstractHistory } from './history/abstract' import type { Matcher } from './create-matcher' -export { History } from './history/base' - -export { AbstractHistory } - export default class VueRouter { static install: () => void; static version: string; @@ -45,6 +41,7 @@ export default class VueRouter { this.afterHooks = [] this.matcher = createMatcher(options.routes || [], this) + let CustomHistory let mode = options.mode || 'hash' this.fallback = mode === 'history' && !supportsPushState && options.fallback !== false if (this.fallback) { @@ -52,19 +49,7 @@ export default class VueRouter { } if (mode && mode.constructor === Object) { - class CustomHistory extends AbstractHistory { - constructor (router, base) { - super(router, base) - - this.init(router, base) - } - - callMethod(name, ...args) { - super[name](...args) - } - } - - Object.assign(CustomHistory.prototype, mode) + CustomHistory = mode.factory(AbstractHistory) mode = mode.name } From daa1b446219ba456135c8760bf91d246779e8c03 Mon Sep 17 00:00:00 2001 From: Kamen Bundev Date: Fri, 14 Sep 2018 18:47:54 +0300 Subject: [PATCH 5/5] fix: flow --- src/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 4147851bf..6ea5d6257 100644 --- a/src/index.js +++ b/src/index.js @@ -48,10 +48,10 @@ export default class VueRouter { mode = 'hash' } - if (mode && mode.constructor === Object) { - CustomHistory = mode.factory(AbstractHistory) + if (options.mode && options.mode.constructor === Object) { + mode = options.mode.name - mode = mode.name + CustomHistory = options.mode.factory(AbstractHistory) } if (!inBrowser && !CustomHistory) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy