-
Notifications
You must be signed in to change notification settings - Fork 1
/
ThemeRegistry.ts
51 lines (44 loc) · 1.36 KB
/
ThemeRegistry.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
import { Theme, ThemeInput } from '../themes';
import { Registry, RegistryInputItem, RegistryItem } from './Registry';
export interface ThemeRegistryItemExtras {}
export type ThemeItem = RegistryItem<Theme> & ThemeRegistryItemExtras;
export type ThemeRegistryInput = RegistryInputItem<ThemeInput>;
export type ThemeCollection = ThemeInput[];
/**
* 🎨 ThemeRegistry
*/
export class ThemeRegistry extends Registry<ThemeItem, ThemeRegistryInput> {
/**
* Adds an Item or an Item value to the registry.
*
* @param item
*/
public async register<
T = ThemeItem | ThemeItem['value'] | ThemeRegistryInput | ThemeRegistryInput['value'],
>(key: string | T, item?: T): Promise<string> {
return key instanceof Theme
? super.register(key.key, key)
: super.register(key as any, item as any);
}
/**
* Typeguard to check a given object is an input value
* @param value
*/
protected isInputValue(value: any): value is ThemeRegistryInput['value'] {
return value instanceof Theme;
}
/**
* Typeguard to check a given object is a registry item
* @param item
*/
protected isItem(item: any): item is ThemeItem {
return item.value && item.value instanceof Theme;
}
/**
* Typeguard to check a given object is a input item
* @param item
*/
protected isInputItem(item: any): item is ThemeRegistryInput {
return item.value && item.value instanceof Theme;
}
}