import { CommunicationObserver , Headers } from '../results' ; export default function completeCommunicationObserver ( callbacks = { } ) { let state = 0 ; const retVal = { next : ( data ) : void => { if ( state === 0 && callbacks . next && data !== null && data !== undefined ) { callbacks . next ( data ) ; } } , error : ( error ) : void => { if ( state === 0 ) { state = 1 ; if ( callbacks . error ) callbacks . error ( error ) ; } } , complete : ( ) : void => { if ( state === 0 ) { state = 2 ; if ( callbacks . complete ) callbacks . complete ( ) ; } } , responseStarted : ( headers , statusCode ? ) : void => { if ( callbacks . responseStarted ) callbacks . responseStarted ( headers , statusCode ) ; } , } ; return retVal ; }