1import { useEffect, useState } from 'preact/hooks'; 2import { rpc } from "rpc"; 3 4class ReactComponentList { 5 constructor(urls) { 6 this.loadingPrm = null; 7 this.urls = urls; 8 this.components = []; 9 } 10 11 uniqify(arr) { 12 return arr.filter((item, index) => arr.indexOf(item) === index); 13 } 14 15 load() { 16 if (!this.loadingPrm) { 17 this.loadingPrm = new Promise(async (resolve) => { 18 const unique_urls = this.uniqify(this.urls); 19 this.components = await Promise.all( 20 unique_urls.map((url) => { 21 return import(url).then((module) => { 22 return module.default; 23 }); 24 }) 25 ); 26 resolve(this.components); 27 }); 28 } 29 return this.loadingPrm; 30 } 31 32} 33 34class ReactPlugins { 35 constructor(urlSlots) { 36 this.urlSlots = urlSlots; 37 this.slots = {}; 38 } 39 40 async getUrls(slot) { 41 const urlSlots = (await this.urlSlots) ?? []; 42 const urls = urlSlots[slot] ?? []; 43 return urls; 44 } 45 46 async loadComponents(slotName) { 47 const urls = await this.getUrls(slotName); 48 this.slots[slotName] = this.slots[slotName] ?? new ReactComponentList(urls); 49 const components = await this.slots[slotName].load(); 50 return components; 51 } 52 53 usePlugins(slot) { 54 const [components, setComponents] = useState([]); 55 useEffect(() => { 56 (async () => { 57 const components = await this.loadComponents(slot); 58 setComponents(components); 59 })(); 60 }, []); 61 return components; 62 } 63} 64 65export const reactPlugins = new ReactPlugins(rpc.ReactPlugins.urlSlots());
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.