import { Injectable } from '@angular/core';
import { Subject, Observable } from 'rxjs';
import { filter } from 'rxjs/operators';
// 通用组件通信类
@Injectable({
providedIn: 'root',
})
export class EventBusService {
private eventSubject: Subject<EBEvent> = new Subject<EBEvent>();
private ob$ = this.eventSubject.asObservable();
public Observable(type: EventType): Observable<EBEvent> {
return this.ob$.pipe(filter(e => e.type === type));
}
send(e: EBEvent) {
this.eventSubject.next(e);
}
constructor() { }
}
export class EBEvent {
constructor(public type: EventType, public data?: any) { }
}
export enum EventType {
// 知识库发送详细内容到聊天窗口
SEND_KNOWLEDGE_DETAIL_TO_WINDOW = 'SEND_KNOWLEDGE_DETAIL_TO_WINDOW'
}