Skip to content

Commit cdee3bc

Browse files
feat(pos-list): support fetch attribute
1 parent a24e3a8 commit cdee3bc

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

docs/elements/components/pos-list/readme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
## Properties
66

7-
| Property | Attribute | Description | Type | Default |
8-
| -------- | --------- | ------------------------------ | -------- | ----------- |
9-
| `rel` | `rel` | URI of the predicate to follow | `string` | `undefined` |
7+
| Property | Attribute | Description | Type | Default |
8+
| -------- | --------- | ----------------------------------------------------------------- | --------- | ----------- |
9+
| `fetch` | `fetch` | Whether listed resources should be fetched before being displayed | `boolean` | `false` |
10+
| `rel` | `rel` | URI of the predicate to follow | `string` | `undefined` |
1011

1112

1213
## Events

elements/src/components.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export namespace Components {
7777
interface PosLabel {
7878
}
7979
interface PosList {
80+
/**
81+
* Whether listed resources should be fetched before being displayed
82+
*/
83+
"fetch": boolean;
8084
/**
8185
* URI of the predicate to follow
8286
*/
@@ -995,6 +999,10 @@ declare namespace LocalJSX {
995999
"onPod-os:resource"?: (event: PosLabelCustomEvent<any>) => void;
9961000
}
9971001
interface PosList {
1002+
/**
1003+
* Whether listed resources should be fetched before being displayed
1004+
*/
1005+
"fetch"?: boolean;
9981006
"onPod-os:resource"?: (event: PosListCustomEvent<any>) => void;
9991007
/**
10001008
* URI of the predicate to follow

elements/src/components/pos-list/pos-list.spec.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,55 @@ describe('pos-list', () => {
119119
expect(el.querySelectorAll('pos-resource')[0]?.getAttribute('uri')).toEqual('https://video.test/video-1');
120120
expect(el.querySelectorAll('pos-resource')[1]?.getAttribute('uri')).toEqual('https://video.test/video-2');
121121
});
122+
123+
it('sets lazy attribute on children if fetch is not present', async () => {
124+
const page = await newSpecPage({
125+
components: [PosList],
126+
html: `
127+
<pos-list rel="http://schema.org/video">
128+
<template>
129+
Test
130+
</template>
131+
</pos-list>`,
132+
});
133+
await page.rootInstance.receiveResource({
134+
relations: () => [
135+
{
136+
predicate: 'http://schema.org/video',
137+
label: 'url',
138+
uris: ['https://video.test/video-1'],
139+
},
140+
],
141+
});
142+
await page.waitForChanges();
143+
144+
const el: HTMLElement = page.root as unknown as HTMLElement;
145+
146+
expect(el.querySelector('pos-resource')?.getAttribute('lazy')).toEqual('');
147+
});
148+
149+
it('does not set lazy attribute on children if fetch is present', async () => {
150+
const page = await newSpecPage({
151+
components: [PosList],
152+
html: `
153+
<pos-list rel="http://schema.org/video" fetch="">
154+
<template>
155+
Test
156+
</template>
157+
</pos-list>`,
158+
});
159+
await page.rootInstance.receiveResource({
160+
relations: () => [
161+
{
162+
predicate: 'http://schema.org/video',
163+
label: 'url',
164+
uris: ['https://video.test/video-1'],
165+
},
166+
],
167+
});
168+
await page.waitForChanges();
169+
170+
const el: HTMLElement = page.root as unknown as HTMLElement;
171+
expect(el.querySelector('pos-resource')?.getAttribute('lazy')).toEqual(null);
172+
});
122173
});

elements/src/components/pos-list/pos-list.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export class PosList implements ResourceAware {
1111
* URI of the predicate to follow
1212
*/
1313
@Prop() rel: string;
14+
/**
15+
* Whether listed resources should be fetched before being displayed
16+
*/
17+
@Prop() fetch: boolean = false;
1418

1519
@Element() host: HTMLDivElement;
1620
@State() error: string = null;
@@ -39,7 +43,7 @@ export class PosList implements ResourceAware {
3943
render() {
4044
if (this.error) return this.error;
4145
const elems = this.items.map(it => (
42-
<pos-resource uri={it} lazy={true} innerHTML={this.templateString} about={it}></pos-resource>
46+
<pos-resource uri={it} lazy={!this.fetch} innerHTML={this.templateString} about={it}></pos-resource>
4347
));
4448
return this.items.length > 0 ? elems : null;
4549
}

0 commit comments

Comments
 (0)