Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active August 8, 2021 19:56
Show Gist options
  • Save WebReflection/2da6e7386fcd37f6d8dc1de3b321779c to your computer and use it in GitHub Desktop.
Save WebReflection/2da6e7386fcd37f6d8dc1de3b321779c to your computer and use it in GitHub Desktop.
// ES2017 Asynchronous Export
// module.js
export default new Promise(async $export => {
const module = await Promise.resolve(
{my: 'module'}
);
$export(module);
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ES2015 consumer
import module from './module.js';
module.then(exports => {
// will log "module"
console.log(exports.my);
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ES2017 consumer
(async () => {
const module = await (
await import('./module.js')
).default;
})();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ES2017 consumer and exporter
export default new Promise(async $export => {
const module = await (
await import('./module.js')
).default;
$export({module, method(){}});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment