import { track } from './inputValueTracking' ; import { setTextContent } from './setTextContent' ; import { initWrapperState as ReactDOMInputInitWrapperState , getHostProps as ReactDOMInputGetHostProps , postMountWrapper as ReactDOMInputPostMountWrapper , updateWrapper as ReactDOMInputUpdateWrapper , } from './ReactDOMInput' ; import { setValueForStyles } from './CSSPropertyOperations' ; import { setValueForProperty } from './DOMPropertyOperations' ; const STYLE = 'style' ; const CHILDREN = 'children' ; const setInitialDOMProperties = ( tag , domElement , nextProps ) => { for ( const propKey in nextProps ) { if ( ! nextProps . hasOwnProperty ( propKey ) ) continue ; const nextProp = nextProps [ propKey ] ; if ( propKey === STYLE ) { setValueForStyles ( domElement as any , nextProp ) ; } else if ( propKey === CHILDREN ) { if ( typeof nextProp === 'string' ) { const canSetTextContent = tag !== 'textarea' || nextProp !== '' ; if ( canSetTextContent ) { setTextContent ( domElement , nextProp ) ; } } else if ( typeof nextProp === 'number' ) { setTextContent ( domElement , nextProp + '' ) ; } } else if ( nextProp != null ) { setValueForProperty ( domElement , propKey , nextProp ) ; } } } ; param domElement param tag param rawProps export const setInitialProperties = ( domElement , tag , rawProps ) => { let props = rawProps ; switch ( tag ) { case 'input' : ReactDOMInputInitWrapperState ( domElement , rawProps ) ; props = ReactDOMInputGetHostProps ( domElement , rawProps ) ; break ; default : break ; } setInitialDOMProperties ( tag , domElement , props ) ; switch ( tag ) { case 'input' : track ( domElement as HTMLInputElement ) ; ReactDOMInputPostMountWrapper ( domElement , rawProps ) ; break ; case 'textarea' : case 'option' : case 'select' : throw new Error ( 'Not Implement' ) ; default : break ; } } ; const updateDOMProperties = ( domElement , updatePayload ) => { for ( let i = 0 ; i < updatePayload . length ; i += 2 ) { const propKey = updatePayload [ i ] ; const propValue = updatePayload [ i + 1 ] ; if ( propKey === STYLE ) { setValueForStyles ( domElement as HTMLElement , propValue ) ; } else if ( propKey === CHILDREN ) { setTextContent ( domElement , propValue ) ; } else { throw new Error ( 'Not Implement' ) ; } } } ; export const updateProperties = ( domElement , updatePayload , tag , lastRawProps , nextRawProps ) : void => { if ( tag === 'input' && nextRawProps . type === 'radio' && nextRawProps . name != null ) { throw new Error ( 'Not Implement' ) ; } updateDOMProperties ( domElement , updatePayload ) ; switch ( tag ) { case 'input' : ReactDOMInputUpdateWrapper ( domElement , nextRawProps ) ; break ; case 'textarea' : case 'select' : throw new Error ( 'Not Implement' ) ; } } ;