-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
67 lines (59 loc) · 1.59 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { Timer, TimerEvents } from '../Timer';
interface BaseNotification<Payload> {
id: string | number;
payload: Payload;
}
export interface PreparedNotification<Payload> extends BaseNotification<Payload> {
options?: Partial<BaseOptions>;
}
export interface LaunchedNotification<Payload> extends BaseNotification<Payload> {
options: BaseOptions;
info: {
timer: Timer<TimerEvents> | null;
};
}
export interface BaseOptions {
/**
* Determines whether the added notification should be removed automatically.
*/
autoRemove: boolean;
/**
* Determines after what time(in milliseconds) the notification should be removed automatically.
*/
autoRemoveTimeout: number;
}
export interface Options extends BaseOptions {
/**
* Determines how many notifications can be displayed.
*/
size: number;
}
export type NotificationEvent = 'add' | 'remove';
export type Disposer = () => void;
export type Handler = () => void;
export interface Notifier<Payload> {
/**
* Contains displayed notifications.
*/
readonly notifications: LaunchedNotification<Payload>[];
/**
* Contains setted options.
*/
readonly options: Options;
/**
* Set options for the current instance.
*/
setOptions: (options: Partial<Options>) => void;
/**
* Add notification.
*/
add: (notification: PreparedNotification<Payload>) => void;
/**
* Remove notification.
*/
remove: (id: string | number) => void;
/**
* Subscribe to notifier events. Return disposer function to unsubscribe from event.
*/
subscribe: (event: NotificationEvent, handler: Handler) => Disposer;
}