/**
 * -------------------------------------------
 * Host Config file.
 *
 * See:
 *   https://github.com/facebook/react/tree/master/packages/react-reconciler
 *   https://github.com/facebook/react/blob/master/packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js
 * -------------------------------------------
 */ import invariant from 'fbjs/lib/invariant' ; import performanceNow from 'performance-now' ; import { createElement } from './element' ; import { applyProps as defaultApplyProps } from './applyProps' ; interface InternalGameObjectProperties { __reactPhaser : { sceneKey : string ; } ; } function appendChild ( parent , child ) { if ( parent instanceof Phaser . Game && child . __reactPhaser . sceneKey ) { const scene = parent . scene . getScene ( child . __reactPhaser . sceneKey ) ; if ( ! scene . children . exists ( child ) ) { scene . add . existing ( child ) ; } } if ( parent instanceof Phaser . GameObjects . GameObject ) { } } function removeChild ( parent , child ) { if ( child . destroy ) { child . destroy ( ) ; } } function insertBefore ( parent , child , beforeChild ) { invariant ( child !== beforeChild , 'PhaserFiber cannot insert node before itself' ) ; if ( parent instanceof Phaser . Game ) { const scene = parent . scene . getScene ( child . __reactPhaser . sceneKey ) ; const childExists = scene . children . exists ( child ) ; const index = scene . children . getIndex ( beforeChild ) ; childExists ? scene . children . moveTo ( child , index ) : scene . children . addAt ( child , index ) ; } } function diffProperties ( phaserElement , type , lastProps , nextProps , rootContainerElement ) { let updatePayload = null ; for ( const propKey in lastProps ) { if ( nextProps . hasOwnProperty ( propKey ) || ! lastProps . hasOwnProperty ( propKey ) || lastProps [ propKey ] == null ) { continue ; } if ( propKey === 'children' ) { } else { if ( ! updatePayload ) { updatePayload = [ ] ; } updatePayload . push ( propKey , null ) ; } } for ( const propKey in nextProps ) { const nextProp = nextProps [ propKey ] ; const lastProp = lastProps != null ? lastProps [ propKey ] : undefined ; if ( ! nextProps . hasOwnProperty ( propKey ) || nextProp === lastProp || ( nextProp == null && lastProp == null ) ) { continue ; } if ( propKey === 'children' ) { } else { if ( ! updatePayload ) { updatePayload = [ ] ; } updatePayload . push ( propKey , nextProp ) ; } } return updatePayload ; } export default { getRootHostContext ( rootContainerInstance ) { return rootContainerInstance ; } , getChildHostContext ( ) { return { } ; } , getChildHostContextForEventComponent ( parentHostContext ) { return parentHostContext ; } , getPublicInstance ( instance ) { return instance ; } , prepareForCommit ( ) { } , resetAfterCommit ( ) { } , createInstance : createElement , hideInstance ( instance ) { if ( instance . setActive ) { instance . setActive ( false ) ; } } , unhideInstance ( instance , props ) { const active = props !== undefined && props !== null && props . hasOwnProperty ( 'active' ) ? props . active : true ; instance . setActive ( active ) ; } , appendInitialChild : appendChild , finalizeInitialChildren ( phaserElement , type , props ) { return false ; } , prepareUpdate ( phaserElement , type , oldProps , newProps , rootContainerInstance , hostContext ) { return diffProperties ( phaserElement , type , oldProps , newProps , rootContainerInstance ) ; } , shouldSetTextContent ( type , props ) { return false ; } , shouldDeprioritizeSubtree ( type , props ) { const isActive = typeof props . active === 'undefined' || props . active === true ; return ! isActive ; } , createTextInstance ( text , rootContainerInstance , internalInstanceHandler ) { invariant ( false , 'react-phaser does not support text instances. Use `<Text /> component` instead.' ) ; } , mountEventComponent ( ) { } , updateEventComponent ( ) { } , handleEventTarget ( ) { } , scheduleTimeout : setTimeout , cancelTimeout : clearTimeout , noTimeout : - 1 , warnsIfNotActing : false , now : performanceNow , isPrimaryRenderer : false , supportsMutation : true , supportsPersistence : false , supportsHydration : false , /**
     * -------------------------------------------
     * Mutation
     * -------------------------------------------
     */ appendChild , appendChildToContainer : appendChild , removeChild , removeChildFromContainer : removeChild , insertBefore , insertInContainerBefore : insertBefore , commitUpdate ( instance , updatePayload , type , oldProps , newProps ) { let applyProps = instance && instance . applyProps ; if ( typeof applyProps !== 'function' ) { applyProps = defaultApplyProps ; } applyProps ( instance , oldProps , newProps ) ; } , commitMount ( instance , updatePayload , type , oldProps , newProps ) { } , commitTextUpdate ( textInstance , oldText , newText ) { } , resetTextContent ( phaserElement ) { } , } ;