import { Observable } from 'rxjs' ; import { debounceTime } from 'rxjs/operators' ; import { UploadTask , UploadTaskSnapshot } from '../interfaces' ; import firebase from 'firebase/compat/app' ; export function fromTask ( task ) { return new Observable < UploadTaskSnapshot > ( subscriber => { const progress = ( snap ) => subscriber . next ( snap ) ; const error = e => subscriber . error ( e ) ; const complete = ( ) => subscriber . complete ( ) ; progress ( task . snapshot ) ; const unsub = task . on ( 'state_changed' , progress ) ; task . then ( snapshot => { progress ( snapshot ) ; complete ( ) ; } , e => { progress ( task . snapshot ) ; error ( e ) ; } ) ; return function unsubscribe ( ) { unsub ( ) ; } ; } ) . pipe ( debounceTime ( 0 ) ) ; }