-
Notifications
You must be signed in to change notification settings - Fork 0
/
life-cycle.interface.ts
45 lines (40 loc) · 1.14 KB
/
life-cycle.interface.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
/**
* @module Lifecycle
*/
/**
* When the application, a module or a component implements this this interface,
* the function will be called after the instance was created.
*/
export interface OnInit {
onInit(): void;
}
/**
* Type guard for OnInit interface
*/
export function implementsOnInit(arg: any): arg is OnInit {
return !!(arg || {}).onInit
}
/**
* When the application, a module or a component implements this this interface,
* the function will be called on any error in the given scope.
* Its possible that multiple onError() functions will be called.
* When you don't return, the next handler will be called. If you return an ErrorHandlerResult
* this will responded if the connection is still opened.
*/
export interface OnError {
/**
* The error handling function for the implementing scope
* @param error the error that occurred
*/
onError(error?: any): void | ErrorHandlerResult;
}
/**
* Type guard for OnError interface
*/
export function implementsOnError(arg: any): arg is OnError {
return !!(arg || {}).onError
}
export interface ErrorHandlerResult {
status: number;
payload?: any;
}