diff options
author | crupest <crupest@outlook.com> | 2020-08-08 18:25:55 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-08-08 18:25:55 +0800 |
commit | 6423c14c71a04bfa15a4289d7a51ff876d2232f8 (patch) | |
tree | 277628fda416f3b0ee4891d46dce7ddbcd0e1d8c | |
parent | 178c90085502e916102f3ecf9c2e2cc38cdb441e (diff) | |
download | timeline-6423c14c71a04bfa15a4289d7a51ff876d2232f8.tar.gz timeline-6423c14c71a04bfa15a4289d7a51ff876d2232f8.tar.bz2 timeline-6423c14c71a04bfa15a4289d7a51ff876d2232f8.zip |
Add observable api for subscription hub.
-rw-r--r-- | Timeline/ClientApp/src/app/data/SubscriptionHub.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Timeline/ClientApp/src/app/data/SubscriptionHub.ts b/Timeline/ClientApp/src/app/data/SubscriptionHub.ts index 8a74c939..24f1885d 100644 --- a/Timeline/ClientApp/src/app/data/SubscriptionHub.ts +++ b/Timeline/ClientApp/src/app/data/SubscriptionHub.ts @@ -1,4 +1,5 @@ import { pull } from 'lodash';
+import { Observable } from 'rxjs';
export type Subscriber<TData> = (data: TData) => void;
@@ -155,6 +156,17 @@ export class SubscriptionHub<TKey, TData> return line.subscribe(subscriber);
}
+ getObservable(key: TKey): Observable<TData> {
+ return new Observable((observer) => {
+ const sub = this.subscribe(key, (data) => {
+ observer.next(data);
+ });
+ return () => {
+ sub.unsubscribe();
+ };
+ });
+ }
+
getLine(key: TKey): ISubscriptionLine<TData> | null {
const keyString = this.keyToString(key);
return this.subscriptionLineMap.get(keyString)?.line ?? null;
|