@yuuvis/client-core 2.4.4 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Triggerable and Subscribable events
|
|
3
|
+
* 1 & T creates an intersection of the literal type 1 and type T, this results in never since nothing can be both 1 and string except for any.
|
|
4
|
+
* 0 dose not extends never or 1, so if T is any, the condition resolves to true.
|
|
3
5
|
*/
|
|
4
|
-
export
|
|
6
|
+
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
7
|
+
export interface YuvEvent<D = any> {
|
|
5
8
|
/**
|
|
6
9
|
* type
|
|
7
10
|
*/
|
|
8
11
|
type: string;
|
|
9
12
|
/**
|
|
10
|
-
* data to be passed along with the event
|
|
13
|
+
* data to be passed along with the event if T is 'any' data is optional
|
|
11
14
|
*/
|
|
12
|
-
data
|
|
15
|
+
data: IsAny<D> extends true ? D | undefined : D;
|
|
13
16
|
}
|
|
14
17
|
/**
|
|
15
18
|
* Mandatory Custom event prefix for all custom YUV events
|
|
@@ -24,3 +27,10 @@ export interface YuvMessage {
|
|
|
24
27
|
timestamp: number;
|
|
25
28
|
source: string;
|
|
26
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Generic call-signature for triggering events.
|
|
32
|
+
* - If `T` is `string`, the `type` parameter will be that string literal type.
|
|
33
|
+
* - If `T` is `any`, the `data` parameter will be optional.
|
|
34
|
+
* - Otherwise `data` is required.
|
|
35
|
+
*/
|
|
36
|
+
export type Trigger = <T = any>(type: T extends string ? T : string, ...data: IsAny<T> extends true ? [data?: T] : [data: T]) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
import { YuvEvent } from './event.interface';
|
|
2
|
+
import { YuvEvent, IsAny } from './event.interface';
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
/**
|
|
5
5
|
* Service for providing triggered events
|
|
@@ -19,12 +19,12 @@ export declare class EventService {
|
|
|
19
19
|
* @param type Type/key of the event
|
|
20
20
|
* @param data Data to be send along with the event
|
|
21
21
|
*/
|
|
22
|
-
trigger(type: string, data?:
|
|
22
|
+
trigger<T extends string = any, D = any>(type: IsAny<T> extends true ? string : T, ...args: IsAny<D> extends true ? [data?: D] : [data: D]): void;
|
|
23
23
|
/**
|
|
24
24
|
* Listen on a triggered event
|
|
25
25
|
* @param types Type/key of the event
|
|
26
26
|
*/
|
|
27
|
-
on(...types: string[]): Observable<YuvEvent
|
|
27
|
+
on<T extends string = any, D = any>(...types: (IsAny<T> extends true ? string : T)[]): Observable<YuvEvent<D>>;
|
|
28
28
|
static ɵfac: i0.ɵɵFactoryDeclaration<EventService, never>;
|
|
29
29
|
static ɵprov: i0.ɵɵInjectableDeclaration<EventService>;
|
|
30
30
|
}
|