これは私が行う方法です。注意してください。テストされていません。
var SystemImport = System.import;
System.import = function (name, options) {
if (Object.prototype.toString.call(name) !== '[object Array]')
return SystemImport.apply(this, arguments);
var self = this,
imports = Promise.all(name.map(function (name) {
return SystemImport.call(self, name); // should i pass options ?
}));
return {
then: function (onfulfill, onreject) {
return imports.then(function (dependencies) {
return onfulfill.apply(null, dependencies);
}, onreject);
}
};
};
このスニペットはSystem.import
、それ自体のラップされたバージョンに置き換えられ、依存関係の配列を使用できるようになります。
「thennable」オブジェクトを返します。これは、準拠した promise 実装で正常に機能するはずです。
メソッドは Promise A+ 仕様にないため.spread
、これは私が考えることができる最も仕様に準拠した方法です...