first working state
This commit is contained in:
parent
0a9b76f9c7
commit
4a0db151d4
23 changed files with 512 additions and 74 deletions
56
services/alert.service.js
Normal file
56
services/alert.service.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
import { Subject } from "rxjs";
|
||||
import { filter } from "rxjs/operators";
|
||||
|
||||
export const alertService = {
|
||||
onAlert,
|
||||
success,
|
||||
error,
|
||||
info,
|
||||
warn,
|
||||
alert,
|
||||
clear,
|
||||
};
|
||||
|
||||
export const AlertType = {
|
||||
Success: "Success",
|
||||
Error: "Error",
|
||||
Info: "Info",
|
||||
Warning: "Warning",
|
||||
};
|
||||
|
||||
const alertSubject = new Subject();
|
||||
const defaultId = "default-alert";
|
||||
|
||||
// enable subscribing to alerts observable
|
||||
function onAlert(id = defaultId) {
|
||||
return alertSubject.asObservable().pipe(filter((x) => x && x.id === id));
|
||||
}
|
||||
|
||||
// convenience methods
|
||||
function success(message, options) {
|
||||
alert({ ...options, type: AlertType.Success, message });
|
||||
}
|
||||
|
||||
function error(message, options) {
|
||||
alert({ ...options, type: AlertType.Error, message });
|
||||
}
|
||||
|
||||
function info(message, options) {
|
||||
alert({ ...options, type: AlertType.Info, message });
|
||||
}
|
||||
|
||||
function warn(message, options) {
|
||||
alert({ ...options, type: AlertType.Warning, message });
|
||||
}
|
||||
|
||||
// core alert method
|
||||
function alert(alert) {
|
||||
alert.id = alert.id || defaultId;
|
||||
alert.autoClose = alert.autoClose === undefined ? true : alert.autoClose;
|
||||
alertSubject.next(alert);
|
||||
}
|
||||
|
||||
// clear alerts
|
||||
function clear(id = defaultId) {
|
||||
alertSubject.next({ id });
|
||||
}
|
1
services/index.js
Normal file
1
services/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export * from "./alert.service";
|
Loading…
Add table
Add a link
Reference in a new issue