Skip to content

Commit

Permalink
feat(runtime-core): failed component resolution should fallback to na…
Browse files Browse the repository at this point in the history
…tive element
  • Loading branch information
yyx990803 committed Mar 25, 2020
1 parent c5beb9f commit cb31eb4
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions packages/runtime-core/src/helpers/resolveAssets.ts
@@ -1,10 +1,5 @@
import { currentRenderingInstance } from '../componentRenderUtils'
import {
currentInstance,
Component,
ComponentInternalInstance,
FunctionalComponent
} from '../component'
import { currentInstance, Component, FunctionalComponent } from '../component'
import { Directive } from '../directives'
import {
camelize,
Expand All @@ -18,20 +13,16 @@ import { warn } from '../warning'
const COMPONENTS = 'components'
const DIRECTIVES = 'directives'

export function resolveComponent(name: string): Component | undefined {
return resolveAsset(COMPONENTS, name)
export function resolveComponent(name: string): Component | string | undefined {
return resolveAsset(COMPONENTS, name) || name
}

export function resolveDynamicComponent(
component: unknown
): Component | string | undefined {
if (!component) return
if (isString(component)) {
return (
resolveAsset(COMPONENTS, component, currentRenderingInstance, false) ||
// fallback to plain element
component
)
return resolveAsset(COMPONENTS, component, false) || component
} else if (isFunction(component) || isObject(component)) {
return component
}
Expand All @@ -45,23 +36,20 @@ export function resolveDirective(name: string): Directive | undefined {
function resolveAsset(
type: typeof COMPONENTS,
name: string,
instance?: ComponentInternalInstance | null,
warnMissing?: boolean
): Component | undefined
// overload 2: directives
function resolveAsset(
type: typeof DIRECTIVES,
name: string,
instance?: ComponentInternalInstance | null
name: string
): Directive | undefined

function resolveAsset(
type: typeof COMPONENTS | typeof DIRECTIVES,
name: string,
instance: ComponentInternalInstance | null = currentRenderingInstance ||
currentInstance,
warnMissing = true
) {
const instance = currentRenderingInstance || currentInstance
if (instance) {
let camelized, capitalized
const registry = instance[type]
Expand Down

0 comments on commit cb31eb4

Please sign in to comment.