Skip to content

Commit

Permalink
Add abortController to export prop, rename option
Browse files Browse the repository at this point in the history
  • Loading branch information
xg-wang committed May 17, 2018
1 parent ae7be04 commit 07fee4e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
7 changes: 4 additions & 3 deletions assets/browser-fetch.js.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
'fetch',
'Headers',
'Request',
'Response'
'Response',
'AbortController'
];
var combinedProps = supportProps;
if (!forcePolyfill) {
if (preferNative) {
combinedProps = supportProps.concat(polyfillProps);
}
combinedProps.forEach(function(prop) {
Expand All @@ -44,7 +45,7 @@
self['default'] = function() {
pending++;

return self.fetch.apply(forcePolyfill ? self : global, arguments).then(function(response){
return self.fetch.apply(preferNative ? global : self, arguments).then(function(response){
response.clone().blob().then(decrement, decrement);
return response;
}, function(reason) {
Expand Down
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ module.exports = {
} while (current.parent.parent && (current = current.parent));
}

this.buildConfig = target.options['ember-fetch'] || {forcePolyfill: true};
this.buildConfig = target.options['ember-fetch'] || { preferNative: false };

target.import('vendor/ember-fetch.js', {
exports: {
default: [
'default',
'Headers',
'Request',
'Response'
'Response',
'AbortController'
]
}
});
Expand All @@ -100,9 +101,11 @@ module.exports = {
*/
treeForVendor: function() {
var browserTree = treeForBrowserFetch();
var forcePolyfill = this.buildConfig.forcePolyfill;
browserTree = map(browserTree, (content) => `var forcePolyfill = ${forcePolyfill}; ${content}`);
browserTree = map(browserTree, (content) => `if (typeof FastBoot === 'undefined') { ${content} }`);
var preferNative = this.buildConfig.preferNative;
browserTree = map(browserTree, (content) => `if (typeof FastBoot === 'undefined') {
var preferNative = ${preferNative};
${content}
}`);
return browserTree;
},

Expand Down

0 comments on commit 07fee4e

Please sign in to comment.