]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(createComponent): rename to defineComponent (#549)
authorChris Fritz <chrisvfritz@gmail.com>
Sun, 22 Dec 2019 15:58:12 +0000 (10:58 -0500)
committerEvan You <yyx990803@gmail.com>
Sun, 22 Dec 2019 15:58:12 +0000 (10:58 -0500)
18 files changed:
packages/runtime-core/__tests__/apiOptions.spec.ts
packages/runtime-core/__tests__/apiSetupContext.spec.ts
packages/runtime-core/__tests__/apiTemplateRef.spec.ts
packages/runtime-core/__tests__/errorHandling.spec.ts
packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts
packages/runtime-core/__tests__/rendererPortal.spec.ts
packages/runtime-core/src/apiDefineComponent.ts [moved from packages/runtime-core/src/apiCreateComponent.ts with 90% similarity]
packages/runtime-core/src/apiOptions.ts
packages/runtime-core/src/component.ts
packages/runtime-core/src/h.ts
packages/runtime-core/src/index.ts
packages/runtime-core/src/renderer.ts
packages/runtime-dom/__tests__/directives/vModel.spec.ts
packages/runtime-dom/__tests__/directives/vShow.spec.ts
packages/runtime-dom/__tests__/modules/class.spec.ts
test-dts/defineComponent.test-d.tsx [moved from test-dts/createComponent.test-d.tsx with 95% similarity]
test-dts/h.test-d.ts
test-dts/tsx.test-d.tsx

index a63d3a66fd3363132a45088a17c3364174918e67..8a0199e3ffb33c3cafeaf9fad66ac0784234aaaa 100644 (file)
@@ -8,13 +8,13 @@ import {
   nextTick,
   renderToString,
   ref,
-  createComponent,
+  defineComponent,
   mockWarn
 } from '@vue/runtime-test'
 
 describe('api: options', () => {
   test('data', async () => {
-    const Comp = createComponent({
+    const Comp = defineComponent({
       data() {
         return {
           foo: 1
@@ -42,7 +42,7 @@ describe('api: options', () => {
   })
 
   test('computed', async () => {
-    const Comp = createComponent({
+    const Comp = defineComponent({
       data() {
         return {
           foo: 1
@@ -78,7 +78,7 @@ describe('api: options', () => {
   })
 
   test('methods', async () => {
-    const Comp = createComponent({
+    const Comp = defineComponent({
       data() {
         return {
           foo: 1
@@ -536,7 +536,7 @@ describe('api: options', () => {
   })
 
   test('accessing setup() state from options', async () => {
-    const Comp = createComponent({
+    const Comp = defineComponent({
       setup() {
         return {
           count: ref(0)
index b9876870ac8378190bd748bd6236e94382a4e2a7..bc3c2065034a5ef259c5bed09ead13c5c95b9466 100644 (file)
@@ -7,7 +7,7 @@ import {
   serializeInner,
   nextTick,
   watch,
-  createComponent,
+  defineComponent,
   triggerEvent,
   TestElement
 } from '@vue/runtime-test'
@@ -16,7 +16,7 @@ import {
 
 describe('api: setup context', () => {
   it('should expose return values to template render context', () => {
-    const Comp = createComponent({
+    const Comp = defineComponent({
       setup() {
         return {
           // ref should auto-unwrap
@@ -53,7 +53,7 @@ describe('api: setup context', () => {
       render: () => h(Child, { count: count.value })
     }
 
-    const Child = createComponent({
+    const Child = defineComponent({
       setup(props: { count: number }) {
         watch(() => {
           dummy = props.count
@@ -82,7 +82,7 @@ describe('api: setup context', () => {
       render: () => h(Child, { count: count.value })
     }
 
-    const Child = createComponent({
+    const Child = defineComponent({
       props: {
         count: Number
       },
@@ -177,7 +177,7 @@ describe('api: setup context', () => {
         })
     }
 
-    const Child = createComponent({
+    const Child = defineComponent({
       props: {
         count: {
           type: Number,
index d164d4571b29708eb80e34490890db5a1fa07291..8ff6b2c59e1f3d4d3cfe6c42bbda122a1e88ad82 100644 (file)
@@ -5,7 +5,7 @@ import {
   render,
   nextTick,
   Ref,
-  createComponent
+  defineComponent
 } from '@vue/runtime-test'
 
 // reference: https://vue-composition-api-rfc.netlify.com/api.html#template-refs
@@ -83,7 +83,7 @@ describe('api: template refs', () => {
     const root = nodeOps.createElement('div')
     const fn = jest.fn()
 
-    const Comp = createComponent(() => () => h('div', { ref: fn }))
+    const Comp = defineComponent(() => () => h('div', { ref: fn }))
     render(h(Comp), root)
     expect(fn.mock.calls[0][0]).toBe(root.children[0])
   })
@@ -94,7 +94,7 @@ describe('api: template refs', () => {
     const fn2 = jest.fn()
     const fn = ref(fn1)
 
-    const Comp = createComponent(() => () => h('div', { ref: fn.value }))
+    const Comp = defineComponent(() => () => h('div', { ref: fn.value }))
 
     render(h(Comp), root)
     expect(fn1.mock.calls).toHaveLength(1)
@@ -113,7 +113,7 @@ describe('api: template refs', () => {
     const fn = jest.fn()
     const toggle = ref(true)
 
-    const Comp = createComponent(() => () =>
+    const Comp = defineComponent(() => () =>
       toggle.value ? h('div', { ref: fn }) : null
     )
     render(h(Comp), root)
index 77ddc8dcf482701755edf2f9e44482640ea2a892..39aebe43c147b5dc81e2689b999c95cbeb63fbeb 100644 (file)
@@ -8,7 +8,7 @@ import {
   ref,
   nextTick,
   mockWarn,
-  createComponent
+  defineComponent
 } from '@vue/runtime-test'
 import { setErrorRecovery } from '../src/errorHandling'
 
@@ -235,7 +235,7 @@ describe('error handling', () => {
       }
     }
 
-    const Child = createComponent(() => () => h('div', { ref }))
+    const Child = defineComponent(() => () => h('div', { ref }))
 
     render(h(Comp), nodeOps.createElement('div'))
     expect(fn).toHaveBeenCalledWith(err, 'ref function')
index dfbf5d595544e34d45bfae580a5f633014ef4439..9e7b498bc5535f590245d480ef077b8a6378f475 100644 (file)
@@ -6,7 +6,7 @@ import {
   mergeProps,
   ref,
   onUpdated,
-  createComponent
+  defineComponent
 } from '@vue/runtime-dom'
 import { mockWarn } from '@vue/runtime-test'
 
@@ -102,7 +102,7 @@ describe('attribute fallthrough', () => {
       }
     }
 
-    const Child = createComponent({
+    const Child = defineComponent({
       props: {
         foo: Number
       },
@@ -179,7 +179,7 @@ describe('attribute fallthrough', () => {
       }
     }
 
-    const GrandChild = createComponent({
+    const GrandChild = defineComponent({
       props: {
         foo: Number
       },
@@ -232,7 +232,7 @@ describe('attribute fallthrough', () => {
       }
     }
 
-    const Child = createComponent({
+    const Child = defineComponent({
       props: ['foo'],
       inheritAttrs: false,
       render() {
@@ -255,7 +255,7 @@ describe('attribute fallthrough', () => {
       }
     }
 
-    const Child = createComponent({
+    const Child = defineComponent({
       props: ['foo'],
       inheritAttrs: false,
       render() {
@@ -287,7 +287,7 @@ describe('attribute fallthrough', () => {
       }
     }
 
-    const Child = createComponent({
+    const Child = defineComponent({
       props: ['foo'],
       render() {
         return [h('div'), h('div')]
@@ -308,7 +308,7 @@ describe('attribute fallthrough', () => {
       }
     }
 
-    const Child = createComponent({
+    const Child = defineComponent({
       props: ['foo'],
       render() {
         return [h('div'), h('div', this.$attrs)]
index c8f82a528bfb81d6ad4034131f664abb4b96bd5e..e5146c49467cbcc107c5207b77330c22ca0f1788 100644 (file)
@@ -3,7 +3,7 @@ import {
   serializeInner,
   render,
   h,
-  createComponent,
+  defineComponent,
   Portal,
   Text,
   Fragment,
@@ -19,7 +19,7 @@ describe('renderer: portal', () => {
     const target = nodeOps.createElement('div')
     const root = nodeOps.createElement('div')
 
-    const Comp = createComponent(() => () =>
+    const Comp = defineComponent(() => () =>
       h(Fragment, [
         h(Portal, { target }, h('div', 'teleported')),
         h('div', 'root')
@@ -37,7 +37,7 @@ describe('renderer: portal', () => {
     const target = ref(targetA)
     const root = nodeOps.createElement('div')
 
-    const Comp = createComponent(() => () =>
+    const Comp = defineComponent(() => () =>
       h(Fragment, [
         h(Portal, { target: target.value }, h('div', 'teleported')),
         h('div', 'root')
@@ -64,7 +64,7 @@ describe('renderer: portal', () => {
       h('div', 'teleported')
     ])
 
-    const Comp = createComponent(() => () =>
+    const Comp = defineComponent(() => () =>
       h(Portal, { target }, children.value)
     )
     render(h(Comp), root)
similarity index 90%
rename from packages/runtime-core/src/apiCreateComponent.ts
rename to packages/runtime-core/src/apiDefineComponent.ts
index 075b289ba7753f4755d3e5cdc2be480f0fb1b778..9244a8161abd051036cdb51f99d86e43325da292 100644 (file)
@@ -11,14 +11,14 @@ import { ExtractPropTypes, ComponentPropsOptions } from './componentProps'
 import { isFunction } from '@vue/shared'
 import { VNodeProps } from './vnode'
 
-// createComponent is a utility that is primarily used for type inference
+// defineComponent is a utility that is primarily used for type inference
 // when declaring components. Type inference is provided in the component
 // options (provided as the argument). The returned value has artifical types
 // for TSX / manual render function / IDE support.
 
 // overload 1: direct setup function
 // (uses user defined props interface)
-export function createComponent<Props, RawBindings = object>(
+export function defineComponent<Props, RawBindings = object>(
   setup: (
     props: Readonly<Props>,
     ctx: SetupContext
@@ -38,7 +38,7 @@ export function createComponent<Props, RawBindings = object>(
 // overload 2: object format with no props
 // (uses user defined props interface)
 // return type is for Vetur and TSX support
-export function createComponent<
+export function defineComponent<
   Props,
   RawBindings,
   D,
@@ -60,7 +60,7 @@ export function createComponent<
 // overload 3: object format with array props declaration
 // props inferred as { [key in PropNames]?: any }
 // return type is for Vetur and TSX support
-export function createComponent<
+export function defineComponent<
   PropNames extends string,
   RawBindings,
   D,
@@ -75,7 +75,7 @@ export function createComponent<
 
 // overload 4: object format with object props declaration
 // see `ExtractPropTypes` in ./componentProps.ts
-export function createComponent<
+export function defineComponent<
   // the Readonly constraint allows TS to treat the type of { required: true }
   // as constant instead of boolean.
   PropsOptions extends Readonly<ComponentPropsOptions>,
@@ -97,6 +97,6 @@ export function createComponent<
 }
 
 // implementation, close to no-op
-export function createComponent(options: unknown) {
+export function defineComponent(options: unknown) {
   return isFunction(options) ? { setup: options } : options
 }
index b50165a272191d95fab4a0528f67c426e592a1c9..8af62b75595337913652e67519b507d3acf11647 100644 (file)
@@ -68,7 +68,7 @@ export interface ComponentOptionsBase<
   inheritAttrs?: boolean
 
   // type-only differentiator to separate OptionWithoutProps from a constructor
-  // type returned by createComponent() or FunctionalComponent
+  // type returned by defineComponent() or FunctionalComponent
   call?: never
   // type-only differentiators for built-in Vnode types
   __isFragment?: never
index 36412420b509da513dcf1a0f6b07983d03e6f77c..0ee06d6b84e4945b67cd1c82fe3c52894ada902c 100644 (file)
@@ -149,7 +149,7 @@ export interface ComponentInternalInstance {
 
 const emptyAppContext = createAppContext()
 
-export function createComponentInstance(
+export function defineComponentInstance(
   vnode: VNode,
   parent: ComponentInternalInstance | null
 ) {
index 7fe3c347457b9aa2e90dae4e9238366ab548aebf..2137be2df1a85dcdad2e5682684d16d14e8b3aa8 100644 (file)
@@ -65,7 +65,7 @@ type RawChildren =
   | VNodeChildren
   | (() => any)
 
-// fake constructor type returned from `createComponent`
+// fake constructor type returned from `defineComponent`
 interface Constructor<P = any> {
   __isFragment?: never
   __isPortal?: never
@@ -130,7 +130,7 @@ export function h<O>(
   children?: RawChildren | RawSlots
 ): VNode
 
-// fake constructor type returned by `createComponent`
+// fake constructor type returned by `defineComponent`
 export function h(type: Constructor, children?: RawChildren): VNode
 export function h<P>(
   type: Constructor<P>,
index 782f93f21108b943724656c93198640dddeeea44..669399c2982669454b0a96ba76d740db0f9ed36d 100644 (file)
@@ -6,7 +6,7 @@ export * from './apiWatch'
 export * from './apiLifecycle'
 export * from './apiInject'
 export { nextTick } from './scheduler'
-export { createComponent } from './apiCreateComponent'
+export { defineComponent } from './apiDefineComponent'
 
 // Advanced API ----------------------------------------------------------------
 
index 9fc0ebb681eb5d266a3599396be1bc6bc0375c3c..013b082ec7361fe73c20ae3b77e91561f7a6758d 100644 (file)
@@ -11,7 +11,7 @@ import {
 } from './vnode'
 import {
   ComponentInternalInstance,
-  createComponentInstance,
+  defineComponentInstance,
   setupStatefulComponent,
   Component,
   Data
@@ -917,7 +917,7 @@ export function createRenderer<
     parentSuspense: HostSuspenseBoundary | null,
     isSVG: boolean
   ) {
-    const instance: ComponentInternalInstance = (initialVNode.component = createComponentInstance(
+    const instance: ComponentInternalInstance = (initialVNode.component = defineComponentInstance(
       initialVNode,
       parentComponent
     ))
index bb263a3a1057815158c65642a1ab4ee766ff6711..cd187ff80af949662022470f03ec0b82dee829b1 100644 (file)
@@ -2,7 +2,7 @@ import {
   createApp,
   h,
   nextTick,
-  createComponent,
+  defineComponent,
   vModelDynamic,
   withDirectives,
   VNode
@@ -29,7 +29,7 @@ beforeEach(() => {
 
 describe('vModel', () => {
   it('should work with text input', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: null }
       },
@@ -60,7 +60,7 @@ describe('vModel', () => {
   })
 
   it('should work with textarea', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: null }
       },
@@ -91,7 +91,7 @@ describe('vModel', () => {
   })
 
   it('should support modifiers', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { number: null, trim: null, lazy: null }
       },
@@ -160,7 +160,7 @@ describe('vModel', () => {
   })
 
   it('should work with checkbox', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: null }
       },
@@ -201,7 +201,7 @@ describe('vModel', () => {
   })
 
   it('should work with checkbox and true-value/false-value', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: null }
       },
@@ -244,7 +244,7 @@ describe('vModel', () => {
   })
 
   it('should work with checkbox and true-value/false-value with object values', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: null }
       },
@@ -287,7 +287,7 @@ describe('vModel', () => {
   })
 
   it(`should support array as a checkbox model`, async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: [] }
       },
@@ -357,7 +357,7 @@ describe('vModel', () => {
   })
 
   it('should work with radio', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: null }
       },
@@ -417,7 +417,7 @@ describe('vModel', () => {
   })
 
   it('should work with single select', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: null }
       },
@@ -473,7 +473,7 @@ describe('vModel', () => {
   })
 
   it('should work with multiple select', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: [] }
       },
index bf093c0945125203e5c3c3fecf27732562702c72..76eef6513e4f40acf1e8d92f050a33a175e0dcab 100644 (file)
@@ -1,6 +1,6 @@
 import {
   withDirectives,
-  createComponent,
+  defineComponent,
   h,
   nextTick,
   VNode
@@ -19,7 +19,7 @@ beforeEach(() => {
 
 describe('runtime-dom: v-show directive', () => {
   test('should check show value is truthy', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: true }
       },
@@ -35,7 +35,7 @@ describe('runtime-dom: v-show directive', () => {
   })
 
   test('should check show value is falsy', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: false }
       },
@@ -51,7 +51,7 @@ describe('runtime-dom: v-show directive', () => {
   })
 
   it('should update show value changed', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: true }
       },
@@ -100,7 +100,7 @@ describe('runtime-dom: v-show directive', () => {
   })
 
   test('should respect display value in style attribute', async () => {
-    const component = createComponent({
+    const component = defineComponent({
       data() {
         return { value: true }
       },
index 85f6e0a3545c71ebc94a719ec8fcc7233580e066..c12780859c0eafec9da9f5a7c2f9e9eccbb5265c 100644 (file)
@@ -1,6 +1,6 @@
 // https://github.com/vuejs/vue/blob/dev/test/unit/features/directives/class.spec.js
 
-import { h, render, createComponent } from '../../src'
+import { h, render, defineComponent } from '../../src'
 
 type ClassItem = {
   value: string | object | string[]
@@ -100,21 +100,21 @@ describe('class', () => {
   })
 
   test('class merge between multiple nested components sharing same element', () => {
-    const component1 = createComponent({
+    const component1 = defineComponent({
       props: {},
       render() {
         return this.$slots.default()[0]
       }
     })
 
-    const component2 = createComponent({
+    const component2 = defineComponent({
       props: {},
       render() {
         return this.$slots.default()[0]
       }
     })
 
-    const component3 = createComponent({
+    const component3 = defineComponent({
       props: {},
       render() {
         return h(
similarity index 95%
rename from test-dts/createComponent.test-d.tsx
rename to test-dts/defineComponent.test-d.tsx
index aba58c7187f74914f31ccbae66913cb921f19c7d..4024f7526dd299ecbc77106908042199053a4def 100644 (file)
@@ -1,5 +1,5 @@
 import { expectError, expectType } from 'tsd'
-import { describe, createComponent, PropType, ref } from './index'
+import { describe, defineComponent, PropType, ref } from './index'
 
 describe('with object props', () => {
   interface ExpectedProps {
@@ -12,7 +12,7 @@ describe('with object props', () => {
     ddd: string[]
   }
 
-  const MyComponent = createComponent({
+  const MyComponent = defineComponent({
     props: {
       a: Number,
       // required should make property non-void
@@ -126,7 +126,7 @@ describe('with object props', () => {
 })
 
 describe('type inference w/ optional props declaration', () => {
-  const MyComponent = createComponent({
+  const MyComponent = defineComponent({
     setup(_props: { msg: string }) {
       return {
         a: 1
@@ -149,14 +149,14 @@ describe('type inference w/ optional props declaration', () => {
 })
 
 describe('type inference w/ direct setup function', () => {
-  const MyComponent = createComponent((_props: { msg: string }) => {})
+  const MyComponent = defineComponent((_props: { msg: string }) => {})
   expectType<JSX.Element>(<MyComponent msg="foo" />)
   expectError(<MyComponent />)
   expectError(<MyComponent msg={1} />)
 })
 
 describe('type inference w/ array props declaration', () => {
-  createComponent({
+  defineComponent({
     props: ['a', 'b'],
     setup(props) {
       // props should be readonly
@@ -179,7 +179,7 @@ describe('type inference w/ array props declaration', () => {
 })
 
 describe('type inference w/ options API', () => {
-  createComponent({
+  defineComponent({
     props: { a: Number },
     setup() {
       return {
index 7998a6c55702f24bb80ad21ca17ef34379028f22..99af6ba5fd209f4a93f19e0b72574f0b1059f5c1 100644 (file)
@@ -2,7 +2,7 @@ import { expectError } from 'tsd'
 import {
   describe,
   h,
-  createComponent,
+  defineComponent,
   ref,
   Fragment,
   Portal,
@@ -71,8 +71,8 @@ describe('h inference w/ plain object component', () => {
   expectError(h(Foo, { foo: 1 }))
 })
 
-describe('h inference w/ createComponent', () => {
-  const Foo = createComponent({
+describe('h inference w/ defineComponent', () => {
+  const Foo = defineComponent({
     props: {
       foo: String,
       bar: {
@@ -93,8 +93,8 @@ describe('h inference w/ createComponent', () => {
   expectError(h(Foo, { bar: 1, foo: 1 }))
 })
 
-describe('h inference w/ createComponent + optional props', () => {
-  const Foo = createComponent({
+describe('h inference w/ defineComponent + optional props', () => {
+  const Foo = defineComponent({
     setup(_props: { foo?: string; bar: number }) {}
   })
 
@@ -109,8 +109,8 @@ describe('h inference w/ createComponent + optional props', () => {
   expectError(h(Foo, { bar: 1, foo: 1 }))
 })
 
-describe('h inference w/ createComponent + direct function', () => {
-  const Foo = createComponent((_props: { foo?: string; bar: number }) => {})
+describe('h inference w/ defineComponent + direct function', () => {
+  const Foo = defineComponent((_props: { foo?: string; bar: number }) => {})
 
   h(Foo, { bar: 1 })
   h(Foo, { bar: 1, foo: 'ok' })
index 34075ed1b93a295e5bd74cb853e27d19deead8d6..387533739c94cc4572444c4f163b0258a0050a01 100644 (file)
@@ -1,4 +1,4 @@
-// TSX w/ createComponent is tested in createComponent.test-d.tsx
+// TSX w/ defineComponent is tested in defineComponent.test-d.tsx
 
 import { expectError, expectType } from 'tsd'
 import { KeepAlive, Suspense, Fragment, Portal } from '@vue/runtime-dom'