Skip to content

Commit

Permalink
perf: use extends over createLocalVue (#934)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh authored Aug 19, 2018
1 parent 71a2e7b commit af45a9d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 9 additions & 3 deletions packages/create-instance/create-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { componentNeedsCompiling, isPlainObject } from 'shared/validators'
import { validateSlots } from './validate-slots'
import createScopedSlots from './create-scoped-slots'
import { extendExtendedComponents } from './extend-extended-components'
import Vue from 'vue'

function compileTemplateForSlots (slots: Object): void {
Object.keys(slots).forEach(key => {
Expand Down Expand Up @@ -43,13 +44,18 @@ const UNSUPPORTED_VERSION_OPTIONS = [

export default function createInstance (
component: Component,
options: Options,
_Vue: Component,
elm?: Element
options: Options
): Component {
// Remove cached constructor
delete component._Ctor

const _Vue = options.localVue
? options.localVue.extend()
: Vue.extend()

// make sure all extends are based on this instance
_Vue.options._base = _Vue

if (
vueVersion < 2.3 &&
typeof component === 'function' &&
Expand Down
6 changes: 2 additions & 4 deletions packages/server-test-utils/src/renderToString.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Vue from 'vue'
import createInstance from 'create-instance'
import { throwError } from 'shared/util'
import { createRenderer } from 'vue-server-renderer'
import testUtils from '@vue/test-utils'
import { mergeOptions } from 'shared/merge-options'
import config from './config'

Expand All @@ -28,11 +27,10 @@ export default function renderToString (
if (options.attachToDocument) {
throwError(`you cannot use attachToDocument with ` + `renderToString`)
}
const vueConstructor = testUtils.createLocalVue(options.localVue)

const vm = createInstance(
component,
mergeOptions(options, config),
vueConstructor
mergeOptions(options, config)
)
let renderedString = ''

Expand Down
6 changes: 1 addition & 5 deletions packages/test-utils/src/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Vue from 'vue'
import VueWrapper from './vue-wrapper'
import createInstance from 'create-instance'
import createElement from './create-element'
import createLocalVue from './create-local-vue'
import errorHandler from './error-handler'
import { findAllVueComponentsFromVm } from './find-vue-components'
import { mergeOptions } from 'shared/merge-options'
Expand All @@ -27,17 +26,14 @@ export default function mount (

// Remove cached constructor
delete component._Ctor
const vueConstructor = createLocalVue(options.localVue)

const elm = options.attachToDocument ? createElement() : undefined

const mergedOptions = mergeOptions(options, config)

const parentVm = createInstance(
component,
mergedOptions,
vueConstructor,
elm
mergedOptions
)

const vm = parentVm.$mount(elm).$refs.vm
Expand Down

0 comments on commit af45a9d

Please sign in to comment.