Skip to content

Commit 3f42d49

Browse files
committed
d.ts - added JSDocs
1 parent cd6c745 commit 3f42d49

4 files changed

+143
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ It is more performant than separate template as there is no content cloning invo
8282
* `slotAdd( name )` clones slot node and inserts immediately after original slot
8383
* `slotsClear()` removes cloned slots from internal DOM
8484

85-
Overrides for `fetched-element` to support following fetch() lifecycle slots `loading`, `error`, `done`;
85+
Overrides for `fetched-element` to support following fetch() lifecycle slots `loading`, `error`, `loaded`;
8686
* `fetch`, `onResponse`, `onResult`, `onError` overrides of `fetch-element` to switch slots according to state change
8787

8888
### Attributes

fetch-element.d.ts

+68-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference lib="dom" />
12
/**
23
* @returns Promise resolved when updated DOM is rendered by calling [requestIdleCallback](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback)
34
* @param cb callback invoked on dom rendered, its return value passed back to wait4DomUpdated promise
@@ -64,20 +65,84 @@ export class FetchElement extends HTMLElement {
6465
status: string;
6566

6667
/**
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)
6869
*/
6970
connectedCallback(): void;
71+
72+
/**
73+
* set to true when fetch is initialized
74+
*/
7075
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+
*/
7179
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+
*/
7288
onResponse(response: any): Promise<any>;
89+
90+
/**
91+
* set by `onResponse()` to 'network error' in case of http code not in 200 range
92+
*/
7393
error: string;
74-
contentType: any;
94+
/**
95+
* response.headers.get( 'content-type' )
96+
*/
97+
contentType: string;
98+
/**
99+
* response.headers
100+
*/
75101
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+
*/
77113
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+
*/
78122
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+
*/
79132
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+
*/
80139
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+
*/
81146
getKeys(obj: any): string[];
82147
}
83148
export default FetchElement;

slotted-element.d.ts

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
export * from "./fetch-element.js";
2+
export class SlottedElement extends FetchElement {
3+
/**
4+
* @see [web component lifecycle](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#using_the_lifecycle_callbacks)
5+
*/
6+
attributeChangedCallback(name: any, oldValue: any, newValue: any): void;
7+
8+
/**
9+
* attribute with id of html element used as template [see light DOM](https://github.com/sashafirsov/css-chain#light-dom-api)
10+
*/
11+
template: string;
12+
13+
/**
14+
* [CssChain](https://github.com/sashafirsov/css-chain) of slotted-elemt children defined by `css`
15+
* @param css
16+
*/
17+
$<T>(css: undefined|string): CssChainCollection<T>&T;
18+
19+
/**
20+
* @see [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
21+
* @param args
22+
*/
23+
fetch( url:Request | string, options ): Promise<any>;
24+
/**
25+
* pre-render callback to massage response data before `render()`
26+
* @param data
27+
*/
28+
setContent(data: any): void;
29+
30+
/**
31+
* read slots from internal DOM. Has to be called before any slots operations.
32+
*/
33+
slotsInit(): void;
34+
35+
/**
36+
* hashmap of slot name to slot used internally
37+
*/
38+
slots: {};
39+
40+
/**
41+
* hide all slots except of named one by setting/removing `hidden` attribute
42+
* @param name
43+
*/
44+
slotOnly(name: string): void;
45+
46+
/**
47+
* remove all slots clones
48+
*/
49+
slotsClear(): void;
50+
51+
/**
52+
* returns node (clone of slot subtree) to be modified before insertion by `slotAdd()`
53+
* @param name
54+
*/
55+
slotClone(name: string): Node;
56+
57+
/**
58+
* adds slot clone node to internal content immediately after original slot
59+
* @param node name or node created by slotClone(name)
60+
*/
61+
slotAdd(node: Node): Node;
62+
63+
/**
64+
* clones slot node and inserts immediately after original slot
65+
* @param nodeName name or node created by slotClone(name)
66+
*/
67+
slotAdd(nodeName: string): Node;
68+
}
69+
export default SlottedElement;
70+
export { $ as CssChain };
71+
import FetchElement from "./fetch-element.js";
72+
import {CssChain as $, CssChainCollection, CssChainT} from "css-chain";

slotted-element.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ SlottedElement extends FE
7777
.remove();
7878
}
7979

80-
slotClone( name ) // create slot to be modified before by slotAdd(node)
80+
slotClone( name )
8181
{
8282
const slot = this.slots[ name ]
8383
if( !slot )
@@ -88,7 +88,7 @@ SlottedElement extends FE
8888
return ret;
8989
}
9090

91-
slotAdd( node ) // name or node created by slotClone(name)
91+
slotAdd( node )
9292
{
9393
const slot = node.slot ? node: this.slotClone( node )
9494
, ref = this.$(`slot[name="${node.slot || node}"]`);

0 commit comments

Comments
 (0)