Social Media Photo by Matteo Maretto on Unsplash
A customElements like registry for user-land libraries.
Based on Some Web Components Hints post idea, but without polluting the customElements
registry.
Compatible down to IE10, or even IE9 (with setTimeout
polyfill), and every other browser, for a total of 272 bytes once minified and gzipped.
import {define, get, whenDefined} from 'custom-libraries';
// const {define, get, whenDefined} = require('custom-libraries');
// <script src="//unpkg.com/custom-libraries">customLibraries</script>
whenDefined('my-lib').then(myLib => {
// myLib is defined and passed along
// get('my-lib') === myLib
});
setTimeout(() => {
define('my-lib', {any: 'value'});
});