Repository navigation
Expand file tree
/
Copy pathindex.d.ts
More file actions
192 lines (169 loc) · 5.27 KB
/
Copy pathindex.d.ts
File metadata and controls
192 lines (169 loc) · 5.27 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
interface IHookedElementsComponent {
/**
* Always triggered once per node => definition, like a `constructor`.
* Ideal to setup anything as a one off operation.
* `this.element` will point at the node handled by this instance.
* If not provided it will default to:
* `function init() { render(this); }`
* The `render(component)` is exported, to enable a custom `init()`.
*/
init?(): void;
/**
* Triggered once the node is live.
*/
connected?(): void;
/**
* Triggered once the node is lost/removed.
* If `useEffect` was used, and returned a callback.
* this will always trigger *after* that callback.
*/
disconnected?(): void;
/**
* Triggered when an attribute in the `observedAttributes` list changes or,
* if `observedAttributes` is not defined, for any attribute changes.
*/
attributeChanged?(
attributeName: string,
newValue: string | null,
oldValue: string | null
): void;
/**
* Optionally you can specify one or more attribute to observe.
* If empty, or not provided, but `attributeChanged()` method exists,
* all attributes changes are notified.
*/
observedAttributes?: Array<string>;
/**
* A method to define rendering logic, automatically
* augmented for hooks such as `useState` and others.
* The `element` is bound and passed along each time.
* It's the exact same `element` retrieved via `this.element`.
*/
render(element: Element): any
/**
* Any event can be defined as method.
* Example: `onClick` or `onCustomEvent`.
*/
onEventName?(event: Event): void;
/**
* Ane event could optionally have `Options` used as third argument,
* when the event is added via `addEventListener`: `false` by default.
*/
onEventNameOptions?: boolean | object;
/**
* Any property, method, or accessor, reflected via prototypal inheritance.
*/
[k: string]: any;
}
declare const hookedElements: {
/**
* Defines a hooked component via a selector and a literal,
* with a `render()` method, or a function, used as `render()`.
* The function will receive the `element` as bound argument.
*
* @example
* define(selector, element => {} || {
* init() { this.element; },
* connected() {},
* disconnected() {},
* attributeChanged(name, newValue, oldValue) {},
* observedAttributes: [],
* onEventName(event) {},
* onEventNameOptions: false
* });
*/
define(
selector: string,
component: Function | IHookedElementsComponent
): void;
/**
* Defines asynchronously a wicked element via a selector and a callback.
* The callback must return a Promise that resolves through a component
* definition.
*
* @example
* defineAsync(selector, () => import('/comp.js'));
*/
defineAsync(
selector: string,
callback: Function
): void;
/**
* Retrieves a hooked element definition.
*/
get(selector: string): void | IHookedElementsComponent;
/**
* Force/upgrade a specific node, if it matches any defined selector.
*/
upgrade(element: Element): void;
/**
* Resolves once a specific selector gets defined.
*/
whenDefined(selector: string): Promise<void>;
/**
* Similar to React `useState` with an extra `options` parameter,
* to define if the change should be triggered `async`,
* which is `false` by default, or `always`, also false by default,
* meaning changes with same value won't trigger a `render()`.
* @see https://reactjs.org/docs/hooks-reference.html#usestate
*/
useState(
initialValue: any,
options?: {async?: boolean, always?: boolean}
): [any, Function];
/**
* Similar to React `useEffect`, and if the effect returned a callback,
* it will be triggered eventually *before* `disconnected()` method, if any.
* @see https://reactjs.org/docs/hooks-reference.html#useeffect
*/
useEffect(didUpdate: Function): void;
/**
* Similar to React `useLayoutEffect`.
* @see https://reactjs.org/docs/hooks-reference.html#uselayouteffect
*/
useLayoutEffect(didUpdate: Function): void;
/**
* Similar to React `useContext`, accepts a `Context` object.
* @see https://reactjs.org/docs/hooks-reference.html#usecontext
*/
useContext(Context: object): any;
/**
* Similar to `React.createContext`. Returns a `Context` object.
* @see https://reactjs.org/docs/hooks-reference.html#usecontext
*/
createContext(object: object): object;
/**
* Similar to React `useReducer`, returns the current `state`
* paired with a `dispatch` method.
* @see https://reactjs.org/docs/hooks-reference.html#usereducer
*/
useReducer(
reducer: Function,
initialState: any,
init?: Function
): [any, Function];
/**
* Similar to React `useCallback`, returns a `memoized` callback.
* @see https://reactjs.org/docs/hooks-reference.html#usecallback
*/
useCallback(
fn: Function,
deps: any[]
): Function;
/**
* Similar to React `useMemo`, returns a `memoized` value.
* @see https://reactjs.org/docs/hooks-reference.html#usememo
*/
useMemo(
fn: Function,
deps: any[]
): any;
/**
* Similar to React `useRef`, returns a `{current: value}` object.
* @see https://reactjs.org/docs/hooks-reference.html#useref
*/
useRef(
initialValue?: any
): {current: any};
};
export = hookedElements;