Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 881297b

Browse files
StepaZolSZolin
and
SZolin
authored
feat(notifier-service): Expose actionStream in Notifier Service (#214)
Co-authored-by: SZolin <SZolin@stream.ru>
1 parent e32f5d7 commit 881297b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

‎projects/angular-notifier/src/lib/services/notifier.service.spec.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { inject, TestBed } from '@angular/core/testing';
2+
import { Subject } from 'rxjs';
23

34
import { NotifierAction } from '../models/notifier-action.model';
45
import { NotifierConfig } from '../models/notifier-config.model';
@@ -170,6 +171,16 @@ describe('Notifier Service', () => {
170171
it('should return the configuration', () => {
171172
expect(service.getConfig()).toEqual(testNotifierConfig);
172173
});
174+
175+
it('should return the notification action', () => {
176+
const testNotificationId = 'ID_FAKE';
177+
const expectedAction: NotifierAction = {
178+
payload: testNotificationId,
179+
type: 'HIDE',
180+
};
181+
service.actionStream.subscribe((action) => expect(action).toEqual(expectedAction));
182+
service.hide(testNotificationId);
183+
});
173184
});
174185

175186
/**
@@ -180,6 +191,7 @@ class MockNotifierQueueService extends NotifierQueueService {
180191
* Last action
181192
*/
182193
public lastAction: NotifierAction;
194+
public actionStream = new Subject<NotifierAction>();
183195

184196
/**
185197
* Push a new action to the queue
@@ -190,5 +202,6 @@ class MockNotifierQueueService extends NotifierQueueService {
190202
*/
191203
public push(action: NotifierAction): void {
192204
this.lastAction = action;
205+
this.actionStream.next(action);
193206
}
194207
}

‎projects/angular-notifier/src/lib/services/notifier.service.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Inject, Injectable } from '@angular/core';
2+
import { Observable } from 'rxjs';
23

4+
import { NotifierAction } from '../models/notifier-action.model';
35
import { NotifierConfig } from '../models/notifier-config.model';
46
import { NotifierNotificationOptions } from '../models/notifier-notification.model';
57
import { NotifierConfigToken } from '../notifier.tokens';
@@ -44,6 +46,15 @@ export class NotifierService {
4446
return this.config;
4547
}
4648

49+
/**
50+
* Get the observable for handling actions
51+
*
52+
* @returns Observable of NotifierAction
53+
*/
54+
public get actionStream(): Observable<NotifierAction> {
55+
return this.queueService.actionStream.asObservable();
56+
}
57+
4758
/**
4859
* API: Show a new notification
4960
*

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /