forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ember-modifier.d.ts
57 lines (56 loc) · 2.7 KB
/
ember-modifier.d.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
// Adds typescripting declarations for ember-modifier since the addon was apparently written in .js
// without .ts support
declare module 'ember-modifier' {
/**
* Functional modifiers consist of a function that receives:
* - The element
* - An array of positional arguments
* - An object of named arguments
*
* This function runs the first time when the element the modifier was applied to is inserted
* into the DOM, and it autotracks while running.Any values that it accesses will be tracked,
* including the arguments it receives, and if any of them changes, the function will run again.
*
* The modifier can also optionally return a destructor.The destructor function will be run just
* before the next update, and when the element is being removed entirely.It should generally
* clean up the changes that the modifier made in the first place.
* @param element - the element the modifier is attached to
* @param params - positional arguments, similar to an Ember helper
* @param hash - named arguments, similar to an Ember helper
*/
// Note: Since these modifiers can be used in a template and allow the consumer to specify any
// type of paramter, ignoring the eslint issue to accommodate. Record<string, unknown> does not
// work well when we're trying to specify different, but valid interfaces for params/hash
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function modifierFunc(element: HTMLElement, params?: Array<any>, hash?: Record<string, any>): Function;
export function modifier(callback: typeof modifierFunc): void;
/**
* Sometimes you may need to do something more complicated than what can be handled by functional
* modifiers. For instance:
* - You may need to inject services and access them
* - You may need fine-grained control of updates, either for performance or convenience reasons,
* and don't want to teardown the state of your modifier every time only to set it up again.
* - You may need to store some local state within your modifier.
*
* In these cases, you can use a class modifier instead.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
class Modifier<T extends { positional?: Array<any>; named?: Record<string, any> }> {
protected args: T;
protected element: HTMLElement;
/**
* Lifecycle event hook run when the helper receives args
*/
didReceiveArguments(): void;
/**
* Run when we are removing the element this modifier is attached to
*/
willRemove(): void;
/**
* Lifecycle event hook run when the element has been inserted into the DOM
*/
didInstall(): void;
constructor(...args: Array<unknown>);
}
export default Modifier;
}