import { VNode , ComponentInstance } from '../shared/svu' ; import { isFunction , isObject } from '../shared' ; import { compile } from '../compiler' ; export let currentInstance = null ; export function createComponentInstance ( vnode ) { const instance = { vnode , type : vnode . type , next : null , subTree : null ! , update : null ! , proxy : null , render : null , effects : null , props : { } , setupState : { } , isMounted : false , bm : null , m : null , bu : null , u : null , um : null , bum : null , } ; return instance ; } export function setupComponent ( instance ) { const Component = instance . type ; const { setup } = Component ; if ( setup ) { currentInstance = instance ; const setupResult = setup ( ) ; currentInstance = null ; handleSetupResult ( instance , setupResult ) ; } } export function handleSetupResult ( instance , setupResult ) { if ( isFunction ( setupResult ) ) { instance . render = setupResult ; } else if ( isObject ( setupResult ) ) { instance . setupState = setupResult ; } finishComponentSetup ( instance ) ; } function finishComponentSetup ( instance ) { const Component = instance . type ; if ( ! instance . render ) { if ( Component . template && ! Component . render ) { Component . render = compile ( Component . template ) ( ) ; } instance . render = Component . render ; } }