Skip to content

Commit 1c4cdd8

Browse files
chrisvfritzyyx990803
authored andcommitted
refactor(createComponent): rename to defineComponent (#549)
1 parent 7d2ae08 commit 1c4cdd8

18 files changed

+74
-74
lines changed

packages/runtime-core/__tests__/apiOptions.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import {
88
nextTick,
99
renderToString,
1010
ref,
11-
createComponent,
11+
defineComponent,
1212
mockWarn
1313
} from '@vue/runtime-test'
1414

1515
describe('api: options', () => {
1616
test('data', async () => {
17-
const Comp = createComponent({
17+
const Comp = defineComponent({
1818
data() {
1919
return {
2020
foo: 1
@@ -42,7 +42,7 @@ describe('api: options', () => {
4242
})
4343

4444
test('computed', async () => {
45-
const Comp = createComponent({
45+
const Comp = defineComponent({
4646
data() {
4747
return {
4848
foo: 1
@@ -78,7 +78,7 @@ describe('api: options', () => {
7878
})
7979

8080
test('methods', async () => {
81-
const Comp = createComponent({
81+
const Comp = defineComponent({
8282
data() {
8383
return {
8484
foo: 1
@@ -536,7 +536,7 @@ describe('api: options', () => {
536536
})
537537

538538
test('accessing setup() state from options', async () => {
539-
const Comp = createComponent({
539+
const Comp = defineComponent({
540540
setup() {
541541
return {
542542
count: ref(0)

packages/runtime-core/__tests__/apiSetupContext.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
serializeInner,
88
nextTick,
99
watch,
10-
createComponent,
10+
defineComponent,
1111
triggerEvent,
1212
TestElement
1313
} from '@vue/runtime-test'
@@ -16,7 +16,7 @@ import {
1616

1717
describe('api: setup context', () => {
1818
it('should expose return values to template render context', () => {
19-
const Comp = createComponent({
19+
const Comp = defineComponent({
2020
setup() {
2121
return {
2222
// ref should auto-unwrap
@@ -53,7 +53,7 @@ describe('api: setup context', () => {
5353
render: () => h(Child, { count: count.value })
5454
}
5555

56-
const Child = createComponent({
56+
const Child = defineComponent({
5757
setup(props: { count: number }) {
5858
watch(() => {
5959
dummy = props.count
@@ -82,7 +82,7 @@ describe('api: setup context', () => {
8282
render: () => h(Child, { count: count.value })
8383
}
8484

85-
const Child = createComponent({
85+
const Child = defineComponent({
8686
props: {
8787
count: Number
8888
},
@@ -177,7 +177,7 @@ describe('api: setup context', () => {
177177
})
178178
}
179179

180-
const Child = createComponent({
180+
const Child = defineComponent({
181181
props: {
182182
count: {
183183
type: Number,

packages/runtime-core/__tests__/apiTemplateRef.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
render,
66
nextTick,
77
Ref,
8-
createComponent
8+
defineComponent
99
} from '@vue/runtime-test'
1010

1111
// reference: https://vue-composition-api-rfc.netlify.com/api.html#template-refs
@@ -83,7 +83,7 @@ describe('api: template refs', () => {
8383
const root = nodeOps.createElement('div')
8484
const fn = jest.fn()
8585

86-
const Comp = createComponent(() => () => h('div', { ref: fn }))
86+
const Comp = defineComponent(() => () => h('div', { ref: fn }))
8787
render(h(Comp), root)
8888
expect(fn.mock.calls[0][0]).toBe(root.children[0])
8989
})
@@ -94,7 +94,7 @@ describe('api: template refs', () => {
9494
const fn2 = jest.fn()
9595
const fn = ref(fn1)
9696

97-
const Comp = createComponent(() => () => h('div', { ref: fn.value }))
97+
const Comp = defineComponent(() => () => h('div', { ref: fn.value }))
9898

9999
render(h(Comp), root)
100100
expect(fn1.mock.calls).toHaveLength(1)
@@ -113,7 +113,7 @@ describe('api: template refs', () => {
113113
const fn = jest.fn()
114114
const toggle = ref(true)
115115

116-
const Comp = createComponent(() => () =>
116+
const Comp = defineComponent(() => () =>
117117
toggle.value ? h('div', { ref: fn }) : null
118118
)
119119
render(h(Comp), root)

packages/runtime-core/__tests__/errorHandling.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
ref,
99
nextTick,
1010
mockWarn,
11-
createComponent
11+
defineComponent
1212
} from '@vue/runtime-test'
1313
import { setErrorRecovery } from '../src/errorHandling'
1414

@@ -235,7 +235,7 @@ describe('error handling', () => {
235235
}
236236
}
237237

238-
const Child = createComponent(() => () => h('div', { ref }))
238+
const Child = defineComponent(() => () => h('div', { ref }))
239239

240240
render(h(Comp), nodeOps.createElement('div'))
241241
expect(fn).toHaveBeenCalledWith(err, 'ref function')

packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
mergeProps,
77
ref,
88
onUpdated,
9-
createComponent
9+
defineComponent
1010
} from '@vue/runtime-dom'
1111
import { mockWarn } from '@vue/runtime-test'
1212

@@ -102,7 +102,7 @@ describe('attribute fallthrough', () => {
102102
}
103103
}
104104

105-
const Child = createComponent({
105+
const Child = defineComponent({
106106
props: {
107107
foo: Number
108108
},
@@ -179,7 +179,7 @@ describe('attribute fallthrough', () => {
179179
}
180180
}
181181

182-
const GrandChild = createComponent({
182+
const GrandChild = defineComponent({
183183
props: {
184184
foo: Number
185185
},
@@ -232,7 +232,7 @@ describe('attribute fallthrough', () => {
232232
}
233233
}
234234

235-
const Child = createComponent({
235+
const Child = defineComponent({
236236
props: ['foo'],
237237
inheritAttrs: false,
238238
render() {
@@ -255,7 +255,7 @@ describe('attribute fallthrough', () => {
255255
}
256256
}
257257

258-
const Child = createComponent({
258+
const Child = defineComponent({
259259
props: ['foo'],
260260
inheritAttrs: false,
261261
render() {
@@ -287,7 +287,7 @@ describe('attribute fallthrough', () => {
287287
}
288288
}
289289

290-
const Child = createComponent({
290+
const Child = defineComponent({
291291
props: ['foo'],
292292
render() {
293293
return [h('div'), h('div')]
@@ -308,7 +308,7 @@ describe('attribute fallthrough', () => {
308308
}
309309
}
310310

311-
const Child = createComponent({
311+
const Child = defineComponent({
312312
props: ['foo'],
313313
render() {
314314
return [h('div'), h('div', this.$attrs)]

packages/runtime-core/__tests__/rendererPortal.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
serializeInner,
44
render,
55
h,
6-
createComponent,
6+
defineComponent,
77
Portal,
88
Text,
99
Fragment,
@@ -19,7 +19,7 @@ describe('renderer: portal', () => {
1919
const target = nodeOps.createElement('div')
2020
const root = nodeOps.createElement('div')
2121

22-
const Comp = createComponent(() => () =>
22+
const Comp = defineComponent(() => () =>
2323
h(Fragment, [
2424
h(Portal, { target }, h('div', 'teleported')),
2525
h('div', 'root')
@@ -37,7 +37,7 @@ describe('renderer: portal', () => {
3737
const target = ref(targetA)
3838
const root = nodeOps.createElement('div')
3939

40-
const Comp = createComponent(() => () =>
40+
const Comp = defineComponent(() => () =>
4141
h(Fragment, [
4242
h(Portal, { target: target.value }, h('div', 'teleported')),
4343
h('div', 'root')
@@ -64,7 +64,7 @@ describe('renderer: portal', () => {
6464
h('div', 'teleported')
6565
])
6666

67-
const Comp = createComponent(() => () =>
67+
const Comp = defineComponent(() => () =>
6868
h(Portal, { target }, children.value)
6969
)
7070
render(h(Comp), root)

packages/runtime-core/src/apiCreateComponent.ts renamed to packages/runtime-core/src/apiDefineComponent.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import { ExtractPropTypes, ComponentPropsOptions } from './componentProps'
1111
import { isFunction } from '@vue/shared'
1212
import { VNodeProps } from './vnode'
1313

14-
// createComponent is a utility that is primarily used for type inference
14+
// defineComponent is a utility that is primarily used for type inference
1515
// when declaring components. Type inference is provided in the component
1616
// options (provided as the argument). The returned value has artifical types
1717
// for TSX / manual render function / IDE support.
1818

1919
// overload 1: direct setup function
2020
// (uses user defined props interface)
21-
export function createComponent<Props, RawBindings = object>(
21+
export function defineComponent<Props, RawBindings = object>(
2222
setup: (
2323
props: Readonly<Props>,
2424
ctx: SetupContext
@@ -38,7 +38,7 @@ export function createComponent<Props, RawBindings = object>(
3838
// overload 2: object format with no props
3939
// (uses user defined props interface)
4040
// return type is for Vetur and TSX support
41-
export function createComponent<
41+
export function defineComponent<
4242
Props,
4343
RawBindings,
4444
D,
@@ -60,7 +60,7 @@ export function createComponent<
6060
// overload 3: object format with array props declaration
6161
// props inferred as { [key in PropNames]?: any }
6262
// return type is for Vetur and TSX support
63-
export function createComponent<
63+
export function defineComponent<
6464
PropNames extends string,
6565
RawBindings,
6666
D,
@@ -75,7 +75,7 @@ export function createComponent<
7575

7676
// overload 4: object format with object props declaration
7777
// see `ExtractPropTypes` in ./componentProps.ts
78-
export function createComponent<
78+
export function defineComponent<
7979
// the Readonly constraint allows TS to treat the type of { required: true }
8080
// as constant instead of boolean.
8181
PropsOptions extends Readonly<ComponentPropsOptions>,
@@ -97,6 +97,6 @@ export function createComponent<
9797
}
9898

9999
// implementation, close to no-op
100-
export function createComponent(options: unknown) {
100+
export function defineComponent(options: unknown) {
101101
return isFunction(options) ? { setup: options } : options
102102
}

packages/runtime-core/src/apiOptions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export interface ComponentOptionsBase<
6868
inheritAttrs?: boolean
6969

7070
// type-only differentiator to separate OptionWithoutProps from a constructor
71-
// type returned by createComponent() or FunctionalComponent
71+
// type returned by defineComponent() or FunctionalComponent
7272
call?: never
7373
// type-only differentiators for built-in Vnode types
7474
__isFragment?: never

packages/runtime-core/src/component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export interface ComponentInternalInstance {
149149

150150
const emptyAppContext = createAppContext()
151151

152-
export function createComponentInstance(
152+
export function defineComponentInstance(
153153
vnode: VNode,
154154
parent: ComponentInternalInstance | null
155155
) {

packages/runtime-core/src/h.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type RawChildren =
6565
| VNodeChildren
6666
| (() => any)
6767

68-
// fake constructor type returned from `createComponent`
68+
// fake constructor type returned from `defineComponent`
6969
interface Constructor<P = any> {
7070
__isFragment?: never
7171
__isPortal?: never
@@ -130,7 +130,7 @@ export function h<O>(
130130
children?: RawChildren | RawSlots
131131
): VNode
132132

133-
// fake constructor type returned by `createComponent`
133+
// fake constructor type returned by `defineComponent`
134134
export function h(type: Constructor, children?: RawChildren): VNode
135135
export function h<P>(
136136
type: Constructor<P>,

packages/runtime-core/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export * from './apiWatch'
66
export * from './apiLifecycle'
77
export * from './apiInject'
88
export { nextTick } from './scheduler'
9-
export { createComponent } from './apiCreateComponent'
9+
export { defineComponent } from './apiDefineComponent'
1010

1111
// Advanced API ----------------------------------------------------------------
1212

packages/runtime-core/src/renderer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from './vnode'
1212
import {
1313
ComponentInternalInstance,
14-
createComponentInstance,
14+
defineComponentInstance,
1515
setupStatefulComponent,
1616
Component,
1717
Data
@@ -917,7 +917,7 @@ export function createRenderer<
917917
parentSuspense: HostSuspenseBoundary | null,
918918
isSVG: boolean
919919
) {
920-
const instance: ComponentInternalInstance = (initialVNode.component = createComponentInstance(
920+
const instance: ComponentInternalInstance = (initialVNode.component = defineComponentInstance(
921921
initialVNode,
922922
parentComponent
923923
))

0 commit comments

Comments
 (0)