refactor: adjust component options merge cache strategy

BREAKING CHANGE: optionMergeStrategies functions no longer receive
the component instance as the 3rd argument. The argument was technically
internal in Vue 2 and only used for generating warnings, and should not
be needed in userland code. This removal enables much more efficient
caching of option merging.
This commit is contained in:
Evan You
2021-06-02 10:37:50 -04:00
parent 44996d1a0a
commit 1e35a860b9
4 changed files with 86 additions and 43 deletions

View File

@@ -53,12 +53,7 @@ export interface App<HostElement = any> {
_createRoot?(options: ComponentOptions): ComponentPublicInstance
}
export type OptionMergeFunction = (
to: unknown,
from: unknown,
instance: any,
key: string
) => any
export type OptionMergeFunction = (to: unknown, from: unknown) => any
export interface AppConfig {
// @private
@@ -97,6 +92,13 @@ export interface AppContext {
components: Record<string, Component>
directives: Record<string, Directive>
provides: Record<string | symbol, any>
/**
* Cache for merged/normalized component options
* Each app instance has its own cache because app-level global mixins and
* optionMergeStrategies can affect merge behavior.
*/
cache: WeakMap<ComponentOptions, ComponentOptions>
/**
* Flag for de-optimizing props normalization
* @internal
@@ -137,7 +139,8 @@ export function createAppContext(): AppContext {
mixins: [],
components: {},
directives: {},
provides: Object.create(null)
provides: Object.create(null),
cache: new WeakMap()
}
}