import * as Phaser from 'phaser' ; import { applyProps as defaultApplyProps } from './applyProps' ; import GameObject from './elements/GameObject' ; export interface CreatePhaserComponentConfig < T extends Phaser . GameObjects . GameObject , P > { create : ( props : P , game : Phaser . Game ) => T ; applyProps ? : ( instance : T , oldProps : P , newProps : P ) => any ; } export const TYPES = { GameObject : 'GameObject' , } ; export const ELEMENTS = { GameObject , } ; param { string } type param { Object } props param { Object } root export function createElement ( type , props = { } , root ) { const { create , applyProps = defaultApplyProps } = ELEMENTS [ type ] ; const instance = create ( props , root ) ; instance . applyProps = applyProps . bind ( instance ) ; applyProps ( instance , { } , props ) ; return instance ; }