1- import { Thing } from '@pod-os/core' ;
1+ import { PodOS , Thing } from '@pod-os/core' ;
22import { Component , Element , Event , h , Prop , State } from '@stencil/core' ;
33import { ResourceAware , ResourceEventEmitter , subscribeResource } from '../events/ResourceAware' ;
4+ import { PodOsAware , PodOsEventEmitter , subscribePodOs } from '../events/PodOsAware' ;
45
56@Component ( {
67 tag : 'pos-list' ,
78 shadow : false ,
89} )
9- export class PosList implements ResourceAware {
10+ export class PosList implements PodOsAware , ResourceAware {
1011 /**
1112 * URI of the predicate to follow
1213 */
1314 @Prop ( ) rel : string ;
15+ /**
16+ * URI of a class for which instances will be listed
17+ */
18+ @Prop ( ) ifTypeof : string ;
1419 /**
1520 * Whether listed resources should be fetched before being displayed
1621 */
1722 @Prop ( ) fetch : boolean = false ;
1823
1924 @Element ( ) host : HTMLElement ;
2025 @State ( ) error : string = null ;
26+ @State ( ) os : PodOS ;
2127 @State ( ) resource : Thing ;
2228 @State ( ) items : string [ ] = [ ] ;
2329 @State ( ) templateString : string ;
2430
2531 @Event ( { eventName : 'pod-os:resource' } )
2632 subscribeResource : ResourceEventEmitter ;
33+ @Event ( { eventName : 'pod-os:init' } )
34+ subscribePodOs : PodOsEventEmitter ;
2735
2836 componentWillLoad ( ) {
29- subscribeResource ( this ) ;
37+ if ( this . rel ) subscribeResource ( this ) ;
38+ if ( this . ifTypeof ) subscribePodOs ( this ) ;
3039 const templateElement = this . host . querySelector ( 'template' ) ;
3140 if ( templateElement == null ) {
3241 this . error = 'No template element found' ;
@@ -36,10 +45,14 @@ export class PosList implements ResourceAware {
3645 }
3746
3847 receiveResource = ( resource : Thing ) => {
39- this . items = [ ] ;
4048 if ( this . rel ) this . items = resource . relations ( this . rel ) . flatMap ( relation => relation . uris ) ;
4149 } ;
4250
51+ receivePodOs = async ( os : PodOS ) => {
52+ this . os = os ;
53+ this . items = os . store . findMembers ( this . ifTypeof ) ;
54+ } ;
55+
4356 render ( ) {
4457 if ( this . error ) return this . error ;
4558 const elems = this . items . map ( it => (
0 commit comments