Hi Oleg,
Hmm, I don't like that, It's dependent on the DOM, and can't be used in
universal. Here is an idea for a service:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/';
export type Payload:any;
export interface EventBusMessage {
channel:string,
payload:Payload
}
@Injectable()
export class EventBusService {
public listen:Observable
private next
constructor() {
this.listen = new Observable(observer => {
this.next = observer.next;
return () => (/* nothing to clean */);
})
this.channelEmmiter = this.channelEmitter.bind(this);
this.emit = this.emit.bind(emit);
}
allChannels():Observable<EventBusMessage> {
return listen;
}
channel(channelName:string) :Observable<Payload>{
return list.filter(e => e.cannel === channelName)
.map(e => e.payload)
}
channelEmmiter(channelName) :function(Payload):void{
return (payload) => this.emit({channel:chanelName, payload})
}
emit({channel:string, payload:any}):void {
this.next({channel,payload})
}
}
Untested and all, but you should get the drift ;)
Regards
Sander
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.