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

Function setupStatefulComponent

packages/runtime-core/src/component.ts:829–927  ·  view source on GitHub ↗
(
  instance: ComponentInternalInstance,
  isSSR: boolean,
)

Source from the content-addressed store, hash-verified

827}
828
829function setupStatefulComponent(
830 instance: ComponentInternalInstance,
831 isSSR: boolean,
832) {
833 const Component = instance.type as ComponentOptions
834
835 if (__DEV__) {
836 if (Component.name) {
837 validateComponentName(Component.name, instance.appContext.config)
838 }
839 if (Component.components) {
840 const names = Object.keys(Component.components)
841 for (let i = 0; i < names.length; i++) {
842 validateComponentName(names[i], instance.appContext.config)
843 }
844 }
845 if (Component.directives) {
846 const names = Object.keys(Component.directives)
847 for (let i = 0; i < names.length; i++) {
848 validateDirectiveName(names[i])
849 }
850 }
851 if (Component.compilerOptions && isRuntimeOnly()) {
852 warn(
853 `"compilerOptions" is only supported when using a build of Vue that ` +
854 `includes the runtime compiler. Since you are using a runtime-only ` +
855 `build, the options should be passed via your build tool config instead.`,
856 )
857 }
858 }
859 // 0. create render proxy property access cache
860 instance.accessCache = Object.create(null)
861 // 1. create public instance / render proxy
862 instance.proxy = new Proxy(instance.ctx, PublicInstanceProxyHandlers)
863 if (__DEV__) {
864 exposePropsOnRenderContext(instance)
865 }
866 // 2. call setup()
867 const { setup } = Component
868 if (setup) {
869 pauseTracking()
870 const setupContext = (instance.setupContext =
871 setup.length > 1 ? createSetupContext(instance) : null)
872 const reset = setCurrentInstance(instance)
873 const setupResult = callWithErrorHandling(
874 setup,
875 instance,
876 ErrorCodes.SETUP_FUNCTION,
877 [
878 __DEV__ ? shallowReadonly(instance.props) : instance.props,
879 setupContext,
880 ],
881 )
882 const isAsyncSetup = isPromise(setupResult)
883 resetTracking()
884 reset()
885
886 if ((isAsyncSetup || instance.sp) && !isAsyncWrapper(instance)) {

Callers 1

setupComponentFunction · 0.85

Calls 15

validateDirectiveNameFunction · 0.90
warnFunction · 0.90
pauseTrackingFunction · 0.90
callWithErrorHandlingFunction · 0.90
shallowReadonlyFunction · 0.90
isPromiseFunction · 0.90
resetTrackingFunction · 0.90
isAsyncWrapperFunction · 0.90
markAsyncBoundaryFunction · 0.90
handleErrorFunction · 0.90
validateComponentNameFunction · 0.85

Tested by

no test coverage detected