Skip to content

Instantly share code, notes, and snippets.

@dherman
Last active September 4, 2019 18:13
Show Gist options
  • Save dherman/b15badb4afffa75230a8 to your computer and use it in GitHub Desktop.
Save dherman/b15badb4afffa75230a8 to your computer and use it in GitHub Desktop.
using new.target-style syntax for providing metadata and relative dynamic import to modules
// import default export
import.default("Spinner").then(Spinner => {
widget.appendChild(new Spinner(...))
});
// import namespace object
import.namespace("fs").then(fs => {
fs.readFile(...)
});
// import local metadata
import.metadata.filename
import.metadata.address
// import default export
import.default(["Spinner", "Slider", "Gallery"]).then([Spinner, Slider, Gallery] => {
...
});
// vs
Promise.all(["Spinner", "Slider", "Gallery"].map(import.default)).then([Spinner, Slider, Gallery] => {
...
});
// import namespace object
import.namespace(["fs", "util", "collections"]).then([fs, util, collections] = {
...
});
// vs
Promise.all(["fs", "util", "collections"].map(import.namespace)).then([fs, util, collections] => {
...
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment