import Vue from 'vue' ; import { ReactWrapper } from './react-wrapper' ; import { ReactNodeWithoutRenderProps , ReactRenderProps , ReactWrapperProps , VueSlots } from './react-wrapper.types' ; import { VueChildrenWrapper } from './vue-children-wrapper' ; import { getVueComponentProps , isScopedSlot } from './vue-creator.utils' ; /**
 * Stores the Vue constructor extending its interface with the methods required to map React
 * slots into Vue ones.
 */ export const VueExtended = Vue . extend ( { methods : { param reactProps returns mapSlots ( reactProps ) { const slots = reactProps . slots ?? { } ; if ( reactProps . children ) { slots . default = reactProps . children ; } return Object . entries ( slots ) . reduce < VueSlots > ( ( slotsTypes , [ slotName , slotContent ] ) => { if ( isScopedSlot ( slotContent ) ) { slotsTypes . scopedSlots [ slotName ] = this . createScopedSlot ( slotName , slotContent ) ; } else { slotsTypes . children . push ( this . createVueSlotContent ( slotName , slotContent ) ) ; } return slotsTypes ; } , { children : [ ] , scopedSlots : { } } ) ; } , param slotName param slotContentFactory returns createScopedSlot ( slotName , slotContentFactory ) { return ( data ) => { return this . createVueSlotContent ( slotName , slotContentFactory , data ) ; } ; } , param slotName param slotContent param reactProps returns createVueSlotContent ( slotName , slotContent , reactProps = null ) { return this . $createElement ( VueChildrenWrapper , { props : { slotContent , reactProps } , slot : slotName , ref : slotName } ) ; } } } ) ; param reactWrapper returns export function createVueInstance ( reactWrapper ) { return new VueExtended ( { data : getVueComponentProps ( reactWrapper . props ) , render ( h ) { const reactProps = reactWrapper . props ; const { children , scopedSlots } = this . mapSlots ( reactProps ) ; return h ( reactProps . component , { props : this . $data , scopedSlots , on : reactProps . on } , children ) ; } } ) ; } param vueInstance param reactProps export function updateVueInstance ( vueInstance , reactProps ) { if ( vueInstance ) { const vueProps = getVueComponentProps ( reactProps ) ; Object . assign ( vueInstance , vueProps ) ; vueInstance . $forceUpdate ( ) ; } }