Skip to content

Commit

Permalink
add observable actionStream
Browse files Browse the repository at this point in the history
  • Loading branch information
SZolin authored and SZolin committed Jul 3, 2021
1 parent e32f5d7 commit 3c5b018
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { inject, TestBed } from '@angular/core/testing';
import { Subject } from 'rxjs';

import { NotifierAction } from '../models/notifier-action.model';
import { NotifierConfig } from '../models/notifier-config.model';
Expand Down Expand Up @@ -170,6 +171,16 @@ describe('Notifier Service', () => {
it('should return the configuration', () => {
expect(service.getConfig()).toEqual(testNotifierConfig);
});

it('should return the notification action', () => {
const testNotificationId = 'ID_FAKE';
const expectedAction: NotifierAction = {
payload: testNotificationId,
type: 'HIDE',
};
service.actionStream.subscribe((action) => expect(action).toEqual(expectedAction));
service.hide(testNotificationId);
});
});

/**
Expand All @@ -180,6 +191,7 @@ class MockNotifierQueueService extends NotifierQueueService {
* Last action
*/
public lastAction: NotifierAction;
public actionStream = new Subject<NotifierAction>();

/**
* Push a new action to the queue
Expand All @@ -190,5 +202,6 @@ class MockNotifierQueueService extends NotifierQueueService {
*/
public push(action: NotifierAction): void {
this.lastAction = action;
this.actionStream.next(action);
}
}
11 changes: 11 additions & 0 deletions projects/angular-notifier/src/lib/services/notifier.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs';

import { NotifierAction } from '../models/notifier-action.model';
import { NotifierConfig } from '../models/notifier-config.model';
import { NotifierNotificationOptions } from '../models/notifier-notification.model';
import { NotifierConfigToken } from '../notifier.tokens';
Expand Down Expand Up @@ -44,6 +46,15 @@ export class NotifierService {
return this.config;
}

/**
* Get the observable for handling actions
*
* @returns Observable of NotifierAction
*/
public get actionStream(): Observable<NotifierAction> {
return this.queueService.actionStream.asObservable();
}

/**
* API: Show a new notification
*
Expand Down

0 comments on commit 3c5b018

Please sign in to comment.