--- /dev/null
+describe('api: createApp', () => {
+ test('mount', () => {})
+
+ test('provide', () => {})
+
+ test('component', () => {})
+
+ test('directive', () => {})
+
+ test('use', () => {})
+
+ test.todo('mixin')
+
+ test('config.errorHandler', () => {})
+
+ test('config.warnHandler', () => {})
+
+ test.todo('config.optionsMergeStrategies')
+})
Component,
ComponentRenderProxy,
Data,
- ComponentInstance
+ ComponentInstance,
+ currentRenderingInstance,
+ currentInstance
} from './component'
import { Directive } from './directives'
import { HostNode, RootRenderFunction } from './createRenderer'
import { InjectionKey } from './apiInject'
-import { isFunction } from '@vue/shared'
+import { isFunction, camelize, capitalize } from '@vue/shared'
import { warn } from './warning'
import { createVNode } from './vnode'
instance: ComponentRenderProxy,
trace: string
) => void
- ignoredElements: Array<string | RegExp>
- keyCodes: Record<string, number | number[]>
- optionMergeStrategies: {
- [key: string]: (
- parent: any,
- child: any,
- instance: ComponentRenderProxy
- ) => any
- }
}
export interface AppContext {
devtools: true,
performance: false,
errorHandler: undefined,
- warnHandler: undefined,
- ignoredElements: [],
- keyCodes: {},
- optionMergeStrategies: {}
+ warnHandler: undefined
},
mixins: [],
components: {},
return app
}
}
+
+export function resolveAsset(type: 'components' | 'directives', name: string) {
+ const instance = currentRenderingInstance || currentInstance
+ if (instance) {
+ let camelized
+ let capitalized
+ const local = (instance.type as any)[type]
+ const global = instance.appContext[type]
+ const res =
+ local[name] ||
+ local[(camelized = camelize(name))] ||
+ local[(capitalized = capitalize(name))] ||
+ global[name] ||
+ global[camelized] ||
+ global[capitalized]
+ if (__DEV__ && !res) {
+ warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`)
+ }
+ return res
+ } else if (__DEV__) {
+ warn(
+ `resolve${capitalize(type.slice(0, -1))} ` +
+ `can only be used in render() or setup().`
+ )
+ }
+}
callWithErrorHandling,
callWithAsyncErrorHandling
} from './errorHandling'
-import { AppContext, createAppContext } from './apiCreateApp'
+import { AppContext, createAppContext, resolveAsset } from './apiCreateApp'
export type Data = { [key: string]: unknown }
}
return false
}
+
+export function resolveComponent(name: string): Component | undefined {
+ return resolveAsset('components', name)
+}
} from './component'
import { callWithAsyncErrorHandling, ErrorTypes } from './errorHandling'
import { HostNode } from './createRenderer'
+import { resolveAsset } from './apiCreateApp'
export interface DirectiveBinding {
instance: ComponentRenderProxy | null
return vnode
}
-export function resolveDirective(name: string): Directive {
- // TODO
- return {} as any
-}
-
export function invokeDirectiveHook(
hook: Function | Function[],
instance: ComponentInstance | null,
callWithAsyncErrorHandling(hook, instance, ErrorTypes.DIRECTIVE_HOOK, args)
}
}
+
+export function resolveDirective(name: string): Directive | undefined {
+ return resolveAsset('directives', name)
+}
} from './errorHandling'
// For the compiler
+export { resolveComponent } from './component'
export { applyDirectives, resolveDirective } from './directives'
// Types -----------------------------------------------------------------------