-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom.js
42 lines (35 loc) · 1.08 KB
/
custom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* My Elements (experimental).
*
* Dynamically import just the custom elements that you need!
*
* @see https://github.com/nfreear/elements
* @copyright © Nick Freear, 09-Jan-2022.
* @license MIT
*
* @status beta, my blog
* @since 1.1.0
* @file
*/
import { getOptUse, hasElem } from './src/Options.js';
// Was: export { MyOptionsElement } from './src/components/MyOptionsElement.js';
/**
* Dynamically import just the custom elements that you need!
* @param {string|array} use List or array of tag-names.
* @example await customImport('my-analytics, my-feed');
* @async
*/
export async function customImport (uses = null, base = '.') {
if (hasElem('my-options')) {
await import(`${base}/src/components/MyOptionsElement.js`);
}
const USED = getOptUse(uses).map(async ({ elem, klass }) => {
const mod = await import(`${base}/src/components/${klass}.js`);
return { elem, klass, mod };
});
return Promise.all(USED);
}
export default customImport;
if (hasElem('script[ src *= "/custom.js" ]')) {
customImport().then(MOD => console.debug('Custom load:', MOD));
}