|
| 1 | +/// <reference lib="dom" /> |
1 | 2 | /**
|
2 | 3 | * @returns Promise resolved when updated DOM is rendered by calling [requestIdleCallback](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback)
|
3 | 4 | * @param cb callback invoked on dom rendered, its return value passed back to wait4DomUpdated promise
|
@@ -64,20 +65,84 @@ export class FetchElement extends HTMLElement {
|
64 | 65 | status: string;
|
65 | 66 |
|
66 | 67 | /**
|
67 |
| - * @see [web component lifecycle]( |
| 68 | + * @see [web component lifecycle](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#using_the_lifecycle_callbacks) |
68 | 69 | */
|
69 | 70 | connectedCallback(): void;
|
| 71 | + |
| 72 | + /** |
| 73 | + * set to true when fetch is initialized |
| 74 | + */ |
70 | 75 | initialized: boolean;
|
| 76 | + /** |
| 77 | + * @see [web component lifecycle](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#using_the_lifecycle_callbacks) |
| 78 | + */ |
71 | 79 | attributeChangedCallback(name: any, oldValue: any, newValue: any): void;
|
| 80 | + |
| 81 | + /** |
| 82 | + * callback when `fetch()` is resolved. |
| 83 | + * Sets `status`, `contentType`, `responseHeaders` and resolves the method for data |
| 84 | + * conversion according to content type. |
| 85 | + * @param response |
| 86 | + * @returns data promise from `response.json()` or `response.text()` |
| 87 | + */ |
72 | 88 | onResponse(response: any): Promise<any>;
|
| 89 | + |
| 90 | + /** |
| 91 | + * set by `onResponse()` to 'network error' in case of http code not in 200 range |
| 92 | + */ |
73 | 93 | error: string;
|
74 |
| - contentType: any; |
| 94 | + /** |
| 95 | + * response.headers.get( 'content-type' ) |
| 96 | + */ |
| 97 | + contentType: string; |
| 98 | + /** |
| 99 | + * response.headers |
| 100 | + */ |
75 | 101 | responseHeaders: any;
|
76 |
| - setContent(html: any): void; |
| 102 | + |
| 103 | + /** |
| 104 | + * pre-render callback to massage response data before `render()` |
| 105 | + * @param data |
| 106 | + */ |
| 107 | + setContent(data: any): void; |
| 108 | + |
| 109 | + /** |
| 110 | + * callback which check the contentType and invokes renderer from `mime2mod` map |
| 111 | + * @param result |
| 112 | + */ |
77 | 113 | onResult(result: any): Promise<any>;
|
| 114 | + |
| 115 | + /** |
| 116 | + * callback to override the output HTML according to response outcome. |
| 117 | + * @param data |
| 118 | + * @param contentType |
| 119 | + * @param httpCode |
| 120 | + * @param responseHeaders |
| 121 | + */ |
78 | 122 | render(data: any, contentType: any, httpCode: any, responseHeaders: any): void;
|
| 123 | + |
| 124 | + /** |
| 125 | + * default rendering implementation which triggers data and html transformation |
| 126 | + * @param data |
| 127 | + * @param contentType |
| 128 | + * @param httpCode |
| 129 | + * @param responseHeaders |
| 130 | + * @param args |
| 131 | + */ |
79 | 132 | renderHtml(data: any, contentType: any, httpCode: any, responseHeaders: any, ...args: any[]): Promise<void>;
|
| 133 | + |
| 134 | + /** |
| 135 | + * callback on `fetch()` failure |
| 136 | + * @param error |
| 137 | + * @returns value for rejected promise |
| 138 | + */ |
80 | 139 | onError(error: any): any;
|
| 140 | + |
| 141 | + /** |
| 142 | + * override to limit or define the order of keys on json object to be rendered in table. |
| 143 | + * @param obj |
| 144 | + * @returns array of keys to be shown in HTML |
| 145 | + */ |
81 | 146 | getKeys(obj: any): string[];
|
82 | 147 | }
|
83 | 148 | export default FetchElement;
|
0 commit comments