So, it seems to me that we're talking about two aspects of module loading:
1) Singleton vs. per-instance
Cu.import allows us to share a single object between all the code that
references it.
ES6 modules are not meant to do that.
2) Conditional vs. static
Cu.import allows us to decide *when* we're loading the code for side-effects,
or even *if* we're going to load it at all.
if (needed) {
Cu.import(...);
}
or
XPCOMUtils.defineLazyModuleGetter(this, 'Services',
'resource://gre/modules/Services.jsm');
-----------------
The latter one may be resolved by some future ECMA proposals like:
- https://github.com/domenic/proposal-import-function
- https://github.com/benjamn/reify/blob/master/PROPOSAL.md
The former is a more tricky. I'm not sure how can we, within statement import
world annotate the difference.
In the import-function world we could maybe do:
import('resource://gre/modules/Services.jsm', {singleton: true}).then();
but for static I don't see a semantically compatible way to annotate singleton
reference.
zb.
_______________________________________________
dev-platform mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-platform