import { Observable } from "rxjs/Rx" ; import { ReactiveObject } from "../reactive-object" ; import { ReactiveCommand } from "../reactive-command" ; param source param obj param command export function invokeCommand < TObj extends ReactiveObject , TArg , TResult > ( source , obj , command ) { var commandObservable ; var canExecute ; var isExecuting ; if ( typeof command === "string" ) { commandObservable = obj . whenSingle ( command , true ) . map ( e => e . newPropertyValue ) ; canExecute = commandObservable . map ( c => c . canExecute ) . switch ( ) ; } else { commandObservable = Observable . of ( command ) ; canExecute = command . canExecute ; } var results = source . withLatestFrom ( commandObservable , canExecute , ( v1 , command , canExecute ) => { return { canExecute , command , observedValue : v1 } ; } ) . filter ( o => o . canExecute && o . command != null ) . distinctUntilChanged ( ) . flatMap ( o => { return o . command . execute ( o . observedValue ) ; } ) ; return results ; }