-
Notifications
You must be signed in to change notification settings - Fork 382
/
types.ts
79 lines (64 loc) · 2.22 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
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import type { LightningElement } from '../base-lightning-element';
import type { HostElement } from '../renderer';
export type DataCallback = (value: any) => void;
export type ConfigValue = Record<string, any>;
export type WireAdapterSchemaValue = 'optional' | 'required';
export type ContextValue = Record<string, any>;
export interface WireAdapter {
update(config: ConfigValue, context?: ContextValue): void;
connect(): void;
disconnect(): void;
}
export interface WireAdapterConstructor {
new (callback: DataCallback): WireAdapter;
configSchema?: Record<string, WireAdapterSchemaValue>;
contextSchema?: Record<string, WireAdapterSchemaValue>;
}
export interface WireDef {
method?: (data: any) => void;
adapter: WireAdapterConstructor;
dynamic: string[];
configCallback: ConfigCallback;
}
export interface WireMethodDef extends WireDef {
method: (data: any) => void;
}
export interface WireFieldDef extends WireDef {
method?: undefined;
}
export type ConfigCallback = (component: LightningElement) => ConfigValue;
export interface WireDebugInfo {
data?: any;
config?: ConfigValue;
context?: ContextValue;
wasDataProvisionedForConfig: boolean;
}
export type WireContextSubscriptionCallback = (
subscriptionPayload: WireContextSubscriptionPayload
) => void;
export interface WireContextSubscriptionPayload {
setNewContext(newContext: ContextValue): void;
setDisconnectedCallback(disconnectCallback: () => void): void;
}
export interface ContextConsumer {
provide(newContext: ContextValue): void;
}
export interface ContextProviderOptions {
consumerConnectedCallback: (consumer: ContextConsumer) => void;
consumerDisconnectedCallback?: (consumer: ContextConsumer) => void;
}
export type ContextProvider = (
elmOrComponent: EventTarget,
options: ContextProviderOptions
) => void;
export type RegisterContextProviderFn = (
element: HostElement,
adapterContextToken: string,
onContextSubscription: WireContextSubscriptionCallback
) => void;