MCPcopy
hub / github.com/vuejs/core / resolveInjections

Function resolveInjections

packages/runtime-core/src/componentOptions.ts:794–833  ·  view source on GitHub ↗
(
  injectOptions: ComponentInjectOptions,
  ctx: any,
  checkDuplicateProperties = NOOP as any,
)

Source from the content-addressed store, hash-verified

792}
793
794export function resolveInjections(
795 injectOptions: ComponentInjectOptions,
796 ctx: any,
797 checkDuplicateProperties = NOOP as any,
798): void {
799 if (isArray(injectOptions)) {
800 injectOptions = normalizeInject(injectOptions)!
801 }
802 for (const key in injectOptions) {
803 const opt = injectOptions[key]
804 let injected: unknown
805 if (isObject(opt)) {
806 if ('default' in opt) {
807 injected = inject(
808 opt.from || key,
809 opt.default,
810 true /* treat default function as factory */,
811 )
812 } else {
813 injected = inject(opt.from || key)
814 }
815 } else {
816 injected = inject(opt)
817 }
818 if (isRef(injected)) {
819 // unwrap injected refs (ref #4196)
820 Object.defineProperty(ctx, key, {
821 enumerable: true,
822 configurable: true,
823 get: () => (injected as Ref).value,
824 set: v => ((injected as Ref).value = v),
825 })
826 } else {
827 ctx[key] = injected
828 }
829 if (__DEV__) {
830 checkDuplicateProperties!(OptionTypes.INJECT, key)
831 }
832 }
833}
834
835function callHook(
836 hook: Function,

Callers 2

injectionsFunction · 0.90
applyOptionsFunction · 0.85

Calls 4

isObjectFunction · 0.90
injectFunction · 0.90
isRefFunction · 0.90
normalizeInjectFunction · 0.85

Tested by

no test coverage detected