I like to keep my code modular, so I put this kind of code in a separate file (overrides/extra.js
):
import Ember from 'ember';
Ember.RSVP.configure('onerror', function(error) {
....
});
export default null;
This has only the side effect of configuring Ember.RSVP
but does not export anything of value. I would then import this in app.js
:
import dummy from './overrides/extra';
Is this accepted practice?
Pure and Non Pure Modules A module with side-effects is one that changes the scope in other ways then returning something, and it's effects are not always predictable, and can be affected by outside forces (non pure function).
To conditionally import an ES6 module with JavaScript, we can use the import function. const myModule = await import(moduleName); in an async function to call import with the moduleName string to import the module named moduleName . And then we get the module returned by the promise returned by import with await .
Safari, Chrome, Firefox and Edge all support the ES6 Modules import syntax. Here's what they look like. Simply add type="module" to your script tags and the browser will load them as ES Modules. The browser will follow all import paths, downloading and executing each module only once.
Yes this is accepted if your module doesn't need to export any data, but there's no need to export anything from a module if it's not required:
import Ember from 'ember';
Ember.RSVP.configure('onerror', function(error) {
....
});
app.js:
import './overrides/extra';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With