normalize-scoped-slots.ts — vue Source File
Architecture documentation for normalize-scoped-slots.ts, a typescript file in the vue codebase. 8 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR 81712410_81a9_d297_5ff3_adabfc4f54fd["normalize-scoped-slots.ts"] 22dbd5d8_751a_f3d4_c38c_61927e291141["is-async-placeholder.ts"] 81712410_81a9_d297_5ff3_adabfc4f54fd --> 22dbd5d8_751a_f3d4_c38c_61927e291141 9cbf4a42_c945_bb3f_b3f1_5fa606986612["isAsyncPlaceholder"] 81712410_81a9_d297_5ff3_adabfc4f54fd --> 9cbf4a42_c945_bb3f_b3f1_5fa606986612 a13b4a2c_7af7_bcfd_03a9_13286f908ca0["vnode.ts"] 81712410_81a9_d297_5ff3_adabfc4f54fd --> a13b4a2c_7af7_bcfd_03a9_13286f908ca0 e2ab1319_857b_3d17_7c7a_2e8a814e3415["lang"] 81712410_81a9_d297_5ff3_adabfc4f54fd --> e2ab1319_857b_3d17_7c7a_2e8a814e3415 59b7f477_cf10_ac02_8228_80efc469f4db["normalize-children"] 81712410_81a9_d297_5ff3_adabfc4f54fd --> 59b7f477_cf10_ac02_8228_80efc469f4db 156bf2e1_8a13_f22d_5437_54f14bcef8fa["util"] 81712410_81a9_d297_5ff3_adabfc4f54fd --> 156bf2e1_8a13_f22d_5437_54f14bcef8fa 907f4994_ea28_43b1_7976_0db9f0e97637["component"] 81712410_81a9_d297_5ff3_adabfc4f54fd --> 907f4994_ea28_43b1_7976_0db9f0e97637 5de22f6c_6406_d60a_f5e8_6b3e166124cc["currentInstance"] 81712410_81a9_d297_5ff3_adabfc4f54fd --> 5de22f6c_6406_d60a_f5e8_6b3e166124cc a8c0285c_59b2_d81b_1af0_c0cd9c2afe2d["render.ts"] a8c0285c_59b2_d81b_1af0_c0cd9c2afe2d --> 81712410_81a9_d297_5ff3_adabfc4f54fd dfa00dc1_b5e1_fc4b_364c_221e22660e03["create-functional-component.ts"] dfa00dc1_b5e1_fc4b_364c_221e22660e03 --> 81712410_81a9_d297_5ff3_adabfc4f54fd style 81712410_81a9_d297_5ff3_adabfc4f54fd fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { def } from 'core/util/lang'
import { normalizeChildren } from 'core/vdom/helpers/normalize-children'
import { emptyObject, isArray } from 'shared/util'
import { isAsyncPlaceholder } from './is-async-placeholder'
import type VNode from '../vnode'
import { Component } from 'types/component'
import { currentInstance, setCurrentInstance } from 'v3/currentInstance'
export function normalizeScopedSlots(
ownerVm: Component,
scopedSlots: { [key: string]: Function } | undefined,
normalSlots: { [key: string]: VNode[] },
prevScopedSlots?: { [key: string]: Function }
): any {
let res
const hasNormalSlots = Object.keys(normalSlots).length > 0
const isStable = scopedSlots ? !!scopedSlots.$stable : !hasNormalSlots
const key = scopedSlots && scopedSlots.$key
if (!scopedSlots) {
res = {}
} else if (scopedSlots._normalized) {
// fast path 1: child component re-render only, parent did not change
return scopedSlots._normalized
} else if (
isStable &&
prevScopedSlots &&
prevScopedSlots !== emptyObject &&
key === prevScopedSlots.$key &&
!hasNormalSlots &&
!prevScopedSlots.$hasNormal
) {
// fast path 2: stable scoped slots w/ no normal slots to proxy,
// only need to normalize once
return prevScopedSlots
} else {
res = {}
for (const key in scopedSlots) {
if (scopedSlots[key] && key[0] !== '$') {
res[key] = normalizeScopedSlot(
ownerVm,
normalSlots,
key,
scopedSlots[key]
)
}
}
}
// expose normal slots on scopedSlots
for (const key in normalSlots) {
if (!(key in res)) {
res[key] = proxyNormalSlot(normalSlots, key)
}
}
// avoriaz seems to mock a non-extensible $scopedSlots object
// and when that is passed down this would cause an error
if (scopedSlots && Object.isExtensible(scopedSlots)) {
scopedSlots._normalized = res
}
def(res, '$stable', isStable)
def(res, '$key', key)
def(res, '$hasNormal', hasNormalSlots)
return res
}
function normalizeScopedSlot(vm, normalSlots, key, fn) {
const normalized = function () {
const cur = currentInstance
setCurrentInstance(vm)
let res = arguments.length ? fn.apply(null, arguments) : fn({})
res =
res && typeof res === 'object' && !isArray(res)
? [res] // single vnode
: normalizeChildren(res)
const vnode: VNode | null = res && res[0]
setCurrentInstance(cur)
return res &&
(!vnode ||
(res.length === 1 && vnode.isComment && !isAsyncPlaceholder(vnode))) // #9658, #10391
? undefined
: res
}
// this is a slot using the new v-slot syntax without scope. although it is
// compiled as a scoped slot, render fn users would expect it to be present
// on this.$slots because the usage is semantically a normal slot.
if (fn.proxy) {
Object.defineProperty(normalSlots, key, {
get: normalized,
enumerable: true,
configurable: true
})
}
return normalized
}
function proxyNormalSlot(slots, key) {
return () => slots[key]
}
Domain
Subdomains
Dependencies
- component
- currentInstance
- is-async-placeholder.ts
- isAsyncPlaceholder
- lang
- normalize-children
- util
- vnode.ts
Source
Frequently Asked Questions
What does normalize-scoped-slots.ts do?
normalize-scoped-slots.ts is a source file in the vue codebase, written in typescript. It belongs to the CoreRuntime domain, Observer subdomain.
What functions are defined in normalize-scoped-slots.ts?
normalize-scoped-slots.ts defines 3 function(s): normalizeScopedSlot, normalizeScopedSlots, proxyNormalSlot.
What does normalize-scoped-slots.ts depend on?
normalize-scoped-slots.ts imports 8 module(s): component, currentInstance, is-async-placeholder.ts, isAsyncPlaceholder, lang, normalize-children, util, vnode.ts.
What files import normalize-scoped-slots.ts?
normalize-scoped-slots.ts is imported by 2 file(s): create-functional-component.ts, render.ts.
Where is normalize-scoped-slots.ts in the architecture?
normalize-scoped-slots.ts is located at src/core/vdom/helpers/normalize-scoped-slots.ts (domain: CoreRuntime, subdomain: Observer, directory: src/core/vdom/helpers).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free