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

perf: use extends instead of createLocalVue #934

Merged
merged 1 commit into from
Aug 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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