Skip to content

Commit

Permalink
feature(removeToast): Added removeToast observable. #42
Browse files Browse the repository at this point in the history
  • Loading branch information
CaselIT committed Sep 11, 2016
1 parent d9bcafa commit 9d148f5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/toaster-container.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,21 @@ describe('ToasterContainerComponent with sync ToasterService', () => {
expect(status).toBe('updated');
});

it('removeToast notifies the removeToast subscribers', (done) => {
toasterContainer.ngOnInit();

var toast: Toast = { type: 'info', title: 'default' };
toasterService.pop(toast);

toasterService.removeToast.subscribe(t => {
expect(t.toastId).toEqual(toast.toastId);
expect(t.toastContainerId).toEqual(toast.toastContainerId);
done();
});

toasterService.clear(toast.toastId);
});

it('clearToasts will clear toasts from all containers if toastContainerId is undefined', () => {
toasterContainer.ngOnInit();

Expand Down
1 change: 1 addition & 0 deletions src/toaster-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class ToasterContainerComponent {
toast.timeoutId = null;
}
if (toast.onHideCallback) toast.onHideCallback(toast);
this.toasterService._removeToastSubject.next({ toastId: toast.toastId, toastContainerId: toast.toastContainerId });
}

private removeAllToasts() {
Expand Down
8 changes: 7 additions & 1 deletion src/toaster.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Toast} from './toast';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/share';
import {Observer} from 'rxjs/Observer';
import {Subject} from 'rxjs/Subject';


@Injectable()
Expand All @@ -13,13 +14,18 @@ export class ToasterService {
clearToasts: Observable<IClearWrapper>;
private _clearToasts: Observer<IClearWrapper>;


removeToast: Observable<IClearWrapper>;
/** @internal */
_removeToastSubject: Subject<IClearWrapper>

/**
* Creates an instance of ToasterService.
*/
constructor() {
this.addToast = new Observable<Toast>(observer => this._addToast = observer).share();
this.clearToasts = new Observable<IClearWrapper>(observer => this._clearToasts = observer).share();
this._removeToastSubject = new Subject<IClearWrapper>()
this.removeToast = this._removeToastSubject.share();
}


Expand Down
3 changes: 2 additions & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"removeComments": false,
"noImplicitAny": false,
"declaration": true,
"outDir": "../lib"
"outDir": "../lib",
"stripInternal": true
},
"files": [
"bodyOutputType.ts",
Expand Down

0 comments on commit 9d148f5

Please sign in to comment.