Skip to content

Commit

Permalink
feat(hub connection): connect now allows optionally send data
Browse files Browse the repository at this point in the history
  • Loading branch information
claylaut committed Dec 15, 2017
1 parent e1b2d30 commit 99a6b8e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/hub-connection.ts
Expand Up @@ -66,11 +66,14 @@ export class HubConnection<THub> {
connection$.subscribe();
}

connect(): Observable<void> {
connect(setData?: Dictionary<string>): Observable<void> {
if (this.internalConnStatus$.value === InternalConnectionStatus.connected) {
console.warn(`${this.source} session already connected`);
return emptyNext();
}
if (setData) {
this.setData(setData);
}

return emptyNext().pipe(
switchMap(() => this.internalConnStatus$.pipe(
Expand All @@ -96,9 +99,17 @@ export class HubConnection<THub> {
this.hubConnectionOptions$.next(connection);
}

clearData() {
clearData(...keys: string[]) {
const connection = this.hubConnectionOptions$.value;
connection.data = undefined;

if (keys && connection.data) {
// tslint:disable-next-line:forin
for (const key in keys) {
delete connection.data[key];
}
} else {
connection.data = undefined;
}
this.hubConnectionOptions$.next(connection);
}

Expand Down

0 comments on commit 99a6b8e

Please sign in to comment.