import { runInAction } from 'mobx' ; import { IComponentState , ILinkDisposer , IComponentDefinition } from './interfaces/index' ; import { EventEmitter } from './EventEmitter' ; import { getInputs , getOutputs } from './decorators' ; export function createLink ( state , props , definition ) { const { inputs = [ ] , outputs = [ ] } = definition ; const { model } = state ; var disposers = [ ] ; const inputProperties = inputs . concat ( getInputs ( model ) ) ; const outputProperties = outputs . concat ( getOutputs ( model ) ) ; inputProperties . forEach ( propName => { if ( props . hasOwnProperty ( propName ) && model . hasOwnProperty ( propName ) ) { runInAction ( ( ) => model [ propName ] = props [ propName ] ) ; } } ) ; outputProperties . forEach ( propName => { if ( props . hasOwnProperty ( propName ) && model . hasOwnProperty ( propName ) ) { const event = model [ propName ] as EventEmitter < any > ; if ( event && event instanceof EventEmitter ) { disposers . push ( event . subscribe ( props [ propName ] ) ) ; } } } ) ; return ( ) => { disposers . map ( disposer => disposer ( ) ) ; disposers = [ ] ; } ; }