import * as Rxjs from 'rxjs' ; import * as op from 'rxjs/operators' ; export class Producer { constructor ( private observer ) { } next ( value ? ) { console . log ( `next: ${ value || 'Hit me!' }` ) ; this . observer . next ( value || 'Hit me!' ) ; } error ( err ? ) { console . log ( `error: ${ err }` ) ; this . observer . error ( err ) ; } complete ( ) { console . log ( `complete()` ) ; this . observer . complete ( ) ; } } /**
 * Usage:
 *  const observable$ = play(this); // the PlayComponent instance
 */ export function play ( component ) { const observable$ = new Rxjs . Observable ( ( subscriber ) => { component . producer = new Producer ( subscriber ) ; return { unsubscribe ( ) { subscriber . unsubscribe ( ) ; console . log ( 'Producer unsubscribed!' ) ; alert ( 'Producer unsubscribed!' ) ; } } ; } ) ; return observable$ ; }