|
1 | 1 | // @flow
|
2 | 2 |
|
3 |
| -import Vue from 'vue' |
4 |
| -import cloneDeep from 'lodash/cloneDeep' |
5 |
| - |
6 |
| -function createLocalVue(_Vue: Component = Vue): Component { |
7 |
| - const instance = _Vue.extend() |
8 |
| - |
9 |
| - // clone global APIs |
10 |
| - Object.keys(_Vue).forEach(key => { |
11 |
| - if (!instance.hasOwnProperty(key)) { |
12 |
| - const original = _Vue[key] |
13 |
| - // cloneDeep can fail when cloning Vue instances |
14 |
| - // cloneDeep checks that the instance has a Symbol |
15 |
| - // which errors in Vue < 2.17 (https://github.com/vuejs/vue/pull/7878) |
16 |
| - try { |
17 |
| - instance[key] = |
18 |
| - typeof original === 'object' ? cloneDeep(original) : original |
19 |
| - } catch (e) { |
20 |
| - instance[key] = original |
21 |
| - } |
22 |
| - } |
23 |
| - }) |
24 |
| - |
25 |
| - // config is not enumerable |
26 |
| - instance.config = cloneDeep(Vue.config) |
27 |
| - |
28 |
| - instance.config.errorHandler = Vue.config.errorHandler |
29 |
| - |
30 |
| - // option merge strategies need to be exposed by reference |
31 |
| - // so that merge strats registered by plugins can work properly |
32 |
| - instance.config.optionMergeStrategies = Vue.config.optionMergeStrategies |
33 |
| - |
34 |
| - // make sure all extends are based on this instance. |
35 |
| - // this is important so that global components registered by plugins, |
36 |
| - // e.g. router-link are created using the correct base constructor |
37 |
| - instance.options._base = instance |
38 |
| - |
39 |
| - // compat for vue-router < 2.7.1 where it does not allow multiple installs |
40 |
| - if (instance._installedPlugins && instance._installedPlugins.length) { |
41 |
| - instance._installedPlugins.length = 0 |
42 |
| - } |
43 |
| - const use = instance.use |
44 |
| - instance.use = (plugin, ...rest) => { |
45 |
| - if (plugin.installed === true) { |
46 |
| - plugin.installed = false |
47 |
| - } |
48 |
| - if (plugin.install && plugin.install.installed === true) { |
49 |
| - plugin.install.installed = false |
50 |
| - } |
51 |
| - use.call(instance, plugin, ...rest) |
52 |
| - } |
53 |
| - return instance |
| 3 | +import _createLocalVue from 'shared/create-local-vue' |
| 4 | + |
| 5 | +/** |
| 6 | + * Returns a local vue instance to add components, mixins and install plugins without polluting the global Vue class |
| 7 | + * @param {VueConfig} config |
| 8 | + * @returns {Component} |
| 9 | + */ |
| 10 | +function createLocalVue(config: VueConfig = {}): Component { |
| 11 | + return _createLocalVue(undefined, config) |
54 | 12 | }
|
55 | 13 |
|
56 | 14 | export default createLocalVue
|
0 commit comments