Skip to content

Commit

Permalink
fix(): Fixed Delete confusing suggestion from source code
Browse files Browse the repository at this point in the history
  • Loading branch information
akserg committed Sep 22, 2016
1 parent b3ed3f9 commit 7d3feaf
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions src/toasty.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// This project is licensed under the terms of the MIT license.
// https://github.com/akserg/ng2-toasty

import { Injectable } from '@angular/core';
import { Injectable, EventEmitter } from '@angular/core';
import { isString, isNumber, isFunction } from './toasty.utils';

import { Observable } from 'rxjs/Observable';
import { Subscriber } from 'rxjs/Subscriber';

/**
* Options to configure specific Toast
Expand Down Expand Up @@ -71,30 +70,22 @@ export class ToastyService {
static THEMES: Array<string> = ['default', 'material', 'bootstrap'];
// Init the counter
uniqueCounter: number = 0;
private toastsObservable: Observable<ToastData>;
private toastsSubscriber: Subscriber<ToastData>;

private clearObservable: Observable<number>;
private clearSubscriber: Subscriber<number>;

constructor(private config: ToastyConfig) {
this.toastsObservable = new Observable<ToastData>((subscriber: Subscriber<ToastData>) => {
this.toastsSubscriber = subscriber;
});
this.clearObservable = new Observable<number>((subscriber: Subscriber<number>) => {
this.clearSubscriber = subscriber;
});
}
// ToastData event emitter
private toastsEmitter: EventEmitter<ToastData> = new EventEmitter<ToastData>();
// Clear event emitter
private clearEmitter: EventEmitter<number> = new EventEmitter<number>();

constructor(private config: ToastyConfig) {}

/**
* Get list of toats
*/
getToasts(): Observable<ToastData> {
return this.toastsObservable;
return this.toastsEmitter.asObservable();
}

getClear(): Observable<number> {
return this.clearObservable;
return this.clearEmitter.asObservable();
}

/**
Expand Down Expand Up @@ -192,28 +183,23 @@ export class ToastyService {
// Allows a caller to pass null/0 and override the default. Can also set the default to null/0 to turn off.
toast.timeout = toastyOptions.hasOwnProperty('timeout') ? toastyOptions.timeout : this.config.timeout;


// Push up a new toast item
try {
this.toastsSubscriber.next(toast);
// If we have a onAdd function, call it here
if (toastyOptions.onAdd && isFunction(toastyOptions.onAdd)) {
toastyOptions.onAdd.call(this, toast);
}
} catch (e) {
console.log(e);
console.log('!!! Suggestion: Seems you forget add <ng2-toasty></ng2-toasty> into your html?');
// this.toastsSubscriber.next(toast);
this.toastsEmitter.next(toast);
// If we have a onAdd function, call it here
if (toastyOptions.onAdd && isFunction(toastyOptions.onAdd)) {
toastyOptions.onAdd.call(this, toast);
}
}

// Clear all toasts
clearAll() {
this.clearSubscriber.next(null);
this.clearEmitter.next(null);
}

// Clear the specific one
clear(id: number) {
this.clearSubscriber.next(id);
this.clearEmitter.next(id);
}

// Checks whether the local option is set, if not,
Expand Down

0 comments on commit 7d3feaf

Please sign in to comment.