Skip to content

Commit

Permalink
refactor(types): remove unnecessary PublicAPIComponent type
Browse files Browse the repository at this point in the history
follow up for #1032
  • Loading branch information
yyx990803 committed Apr 24, 2020
1 parent f3a9b51 commit 4f8a6b2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 deletions.
16 changes: 6 additions & 10 deletions packages/runtime-core/src/apiAsyncComponent.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
import {
PublicAPIComponent,
Component,
currentInstance,
ComponentInternalInstance,
isInSSRComponentSetup
} from './component'
import { isFunction, isObject } from '@vue/shared'
import { ComponentPublicInstance } from './componentProxy'
import { createVNode } from './vnode'
import { defineComponent } from './apiDefineComponent'
import { warn } from './warning'
import { ref } from '@vue/reactivity'
import { handleError, ErrorCodes } from './errorHandling'

export type AsyncComponentResolveResult<T = PublicAPIComponent> =
| T
| { default: T } // es modules
export type AsyncComponentResolveResult<T = Component> = T | { default: T } // es modules

export type AsyncComponentLoader<T = any> = () => Promise<
AsyncComponentResolveResult<T>
>

export interface AsyncComponentOptions<T = any> {
loader: AsyncComponentLoader<T>
loadingComponent?: PublicAPIComponent
errorComponent?: PublicAPIComponent
loadingComponent?: Component
errorComponent?: Component
delay?: number
timeout?: number
suspensible?: boolean
Expand All @@ -36,9 +32,9 @@ export interface AsyncComponentOptions<T = any> {
) => any
}

export function defineAsyncComponent<
T extends PublicAPIComponent = { new (): ComponentPublicInstance }
>(source: AsyncComponentLoader<T> | AsyncComponentOptions<T>): T {
export function defineAsyncComponent<T extends Component>(
source: AsyncComponentLoader<T> | AsyncComponentOptions<T>
): T {
if (isFunction(source)) {
source = { loader: source }
}
Expand Down
17 changes: 6 additions & 11 deletions packages/runtime-core/src/apiCreateApp.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
Component,
Data,
validateComponentName,
PublicAPIComponent
} from './component'
import { Component, Data, validateComponentName } from './component'
import { ComponentOptions } from './componentOptions'
import { ComponentPublicInstance } from './componentProxy'
import { Directive, validateDirectiveName } from './directives'
Expand All @@ -18,8 +13,8 @@ export interface App<HostElement = any> {
config: AppConfig
use(plugin: Plugin, ...options: any[]): this
mixin(mixin: ComponentOptions): this
component(name: string): PublicAPIComponent | undefined
component(name: string, component: PublicAPIComponent): this
component(name: string): Component | undefined
component(name: string, component: Component): this
directive(name: string): Directive | undefined
directive(name: string, directive: Directive): this
mount(
Expand Down Expand Up @@ -67,7 +62,7 @@ export interface AppConfig {
export interface AppContext {
config: AppConfig
mixins: ComponentOptions[]
components: Record<string, PublicAPIComponent>
components: Record<string, Component>
directives: Record<string, Directive>
provides: Record<string | symbol, any>
reload?: () => void // HMR only
Expand Down Expand Up @@ -101,7 +96,7 @@ export function createAppContext(): AppContext {
}

export type CreateAppFunction<HostElement> = (
rootComponent: PublicAPIComponent,
rootComponent: Component,
rootProps?: Data | null
) => App<HostElement>

Expand Down Expand Up @@ -172,7 +167,7 @@ export function createAppAPI<HostElement>(
return app
},

component(name: string, component?: PublicAPIComponent): any {
component(name: string, component?: Component): any {
if (__DEV__) {
validateComponentName(name, context.config)
}
Expand Down
3 changes: 3 additions & 0 deletions packages/runtime-core/src/apiDefineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export function defineComponent<
E,
VNodeProps & Props
>
// make the type compatible with `Component`.
// this can be just `typeof options` but it's not supported by API extractor
// yet
} & ComponentOptionsWithoutProps<Props, RawBindings, D, C, M, E, EE>

// overload 3: object format with array props declaration
Expand Down
6 changes: 0 additions & 6 deletions packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ export interface ClassComponent {

export type Component = ComponentOptions | FunctionalComponent<any>

// A type used in public APIs where a component type is expected.
// The constructor type is an artificial type returned by defineComponent().
export type PublicAPIComponent =
| Component
| { new (...args: any[]): ComponentPublicInstance<any, any, any, any, any> }

export { ComponentOptions }

type LifecycleHook = Function[] | null
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
SetupContext,
RenderFunction,
SFCInternalOptions,
PublicAPIComponent,
Component
} from './component'
import {
Expand Down Expand Up @@ -102,7 +101,7 @@ export interface ComponentOptionsBase<
push: (item: any) => void,
parentInstance: ComponentInternalInstance
) => void
components?: Record<string, PublicAPIComponent>
components?: Record<string, Component>
directives?: Record<string, Directive>
inheritAttrs?: boolean
emits?: E | EE[]
Expand Down

1 comment on commit 4f8a6b2

@yyx990803
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted.

Please sign in to comment.