Skip to content

Commit

Permalink
BREAKING CHANGE: drop createComponent (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored Jun 23, 2020
1 parent b11f14c commit a1792de
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 77 deletions.
40 changes: 0 additions & 40 deletions src/component/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,43 +119,3 @@ export function defineComponent<
export function defineComponent(options: any) {
return options as any
}

// overload 1: object format with no props
export function createComponent<RawBindings>(
options: ComponentOptionsWithoutProps<unknown, RawBindings>
): VueProxy<unknown, RawBindings>
// overload 2: object format with array props declaration
// props inferred as { [key in PropNames]?: any }
// return type is for Vetur and TSX support
export function createComponent<
PropNames extends string,
RawBindings = Data,
PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
>(
// prettier-ignore
options: (
ComponentOptionsWithArrayProps<PropNames, RawBindings>) &
Omit<Vue2ComponentOptions<Vue>, keyof ComponentOptionsWithProps<never, never>>
): VueProxy<Readonly<{ [key in PropNames]?: any }>, RawBindings>
// overload 3: object format with object props declaration
// see `ExtractPropTypes` in ./componentProps.ts
export function createComponent<
Props,
RawBindings = Data,
PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
>(
// prettier-ignore
options: (
// prefer the provided Props, otherwise infer it from PropsOptions
HasDefined<Props> extends true
? ComponentOptionsWithProps<PropsOptions, RawBindings, Props>
: ComponentOptionsWithProps<PropsOptions, RawBindings>) &
Omit<Vue2ComponentOptions<Vue>, keyof ComponentOptionsWithProps<never, never>>
): VueProxy<PropsOptions, RawBindings>
// implementation, deferring to defineComponent, but logging a warning in dev mode
export function createComponent(options: any) {
if (__DEV__) {
Vue.util.warn('`createComponent` has been renamed to `defineComponent`.')
}
return defineComponent(options)
}
1 change: 0 additions & 1 deletion src/component/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export {
Data,
createComponent,
defineComponent,
SetupFunction,
SetupContext,
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default plugin
export { default as createElement } from './createElement'
export { SetupContext }
export {
createComponent,
defineComponent,
ComponentRenderProxy,
PropType,
Expand Down
35 changes: 0 additions & 35 deletions test/types/defineComponent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
createComponent,
defineComponent,
createElement as h,
ref,
Expand Down Expand Up @@ -217,38 +216,4 @@ describe('defineComponent', () => {
})
})
})

describe('retro-compatible with createComponent', () => {
it('should still work and warn', () => {
const warn = jest
.spyOn(global.console, 'error')
.mockImplementation(() => null)
const Child = createComponent({
props: { msg: String },
setup(props) {
return () => h('span', props.msg)
},
})

const App = createComponent({
setup() {
const msg = ref('hello')
return () =>
h('div', [
h(Child, {
props: {
msg: msg.value,
},
}),
])
},
})
const vm = new Vue(App).$mount()
expect(vm.$el.querySelector('span').textContent).toBe('hello')
expect(warn.mock.calls[0][0]).toMatch(
'[Vue warn]: `createComponent` has been renamed to `defineComponent`.'
)
warn.mockRestore()
})
})
})

0 comments on commit a1792de

Please sign in to comment.