Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* enhancement (header): a login success message is now shown below the header when a user successfully logs in * fix packages * fix (header): added onDestroy method to unsubscribe from subscription and added tests
- Loading branch information
Showing
9 changed files
with
119 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,4 @@ docs/bin | |
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
*.code-workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
<router-outlet></router-outlet> | ||
</div> | ||
|
||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/app/services/component-communication-event.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { ComponentCommunicationEventService } from './component-communication-event.service'; | ||
|
||
describe('ComponentCommunicationEventService', () => { | ||
let service: ComponentCommunicationEventService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(ComponentCommunicationEventService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Subject, Subscription } from 'rxjs'; | ||
import { filter, map } from 'rxjs/operators'; | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ComponentCommunicationEventService { | ||
|
||
// create a subject to hold data which can be subscribed to. | ||
// you only get the data after you subscribe. | ||
private _subject$ = new Subject(); | ||
|
||
// used in the listening component. | ||
// i.e. this.componentCommunicationEventService = this._componentCommunicationEventService.on(Events.LoginSuccess, () => doSomething()); | ||
on(event: Events, action: () => void): Subscription { | ||
return this._subject$ | ||
.pipe( | ||
// filter down based on event name to any events that are emitted out of the subject from the emit method below. | ||
filter((e: EmitEvent) => e.name === event), | ||
map((e: EmitEvent) => e.value) | ||
) | ||
.subscribe(action); // subscribe to the subject to get the data. | ||
} | ||
|
||
// used in the emitting component. | ||
// i.e. this.componentCommunicationEventService.emit(new EmitEvent(Events.LoginSuccess)); | ||
emit(event: EmitEvent) { | ||
this._subject$.next(event); | ||
} | ||
} | ||
|
||
export class EmitEvent { | ||
constructor(public name: any, public value?: any) { } | ||
} | ||
|
||
// possible events that can be emitted. | ||
export enum Events { | ||
LoginSuccess | ||
} |