Skip to content

Commit 8dbb9e6

Browse files
committed
refactor: minor refactor of basic-loader
1 parent eacb0da commit 8dbb9e6

3 files changed

Lines changed: 21 additions & 22 deletions

File tree

lib/basic-loader-amd.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ define(["exports"], function (_exports) {
66
});
77
_exports.default = void 0;
88

9-
function _load(tag) {
9+
var _load = function _load(tag) {
1010
// attributes example: { 'data-test': 'new-attribute-here' }
1111
return function (url) {
1212
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -36,17 +36,17 @@ define(["exports"], function (_exports) {
3636
element.rel = 'stylesheet';
3737
attr = 'href';
3838
parent = 'head';
39-
} // Inject into document to kick off loading
40-
39+
}
4140

4241
element[attr] = url;
43-
Object.keys(attributes).forEach(function (key) {
44-
element.setAttribute(key, attributes[key]);
45-
});
42+
Object.keys(attributes).forEach(function (name) {
43+
return element.setAttribute(name, attributes[name]);
44+
}); // Inject into document to kick off loading
45+
4646
document[parent].appendChild(element);
4747
});
4848
};
49-
} // exporting a "default" would render the amd package to work differently
49+
}; // exporting a "default" would render the amd package to work differently
5050

5151

5252
var _default = {

lib/basic-loader.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
55
});
66
exports.default = void 0;
77

8-
function _load(tag) {
8+
var _load = function _load(tag) {
99
// attributes example: { 'data-test': 'new-attribute-here' }
1010
return function (url) {
1111
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -35,17 +35,17 @@ function _load(tag) {
3535
element.rel = 'stylesheet';
3636
attr = 'href';
3737
parent = 'head';
38-
} // Inject into document to kick off loading
39-
38+
}
4039

4140
element[attr] = url;
42-
Object.keys(attributes).forEach(function (key) {
43-
element.setAttribute(key, attributes[key]);
44-
});
41+
Object.keys(attributes).forEach(function (name) {
42+
return element.setAttribute(name, attributes[name]);
43+
}); // Inject into document to kick off loading
44+
4545
document[parent].appendChild(element);
4646
});
4747
};
48-
} // exporting a "default" would render the amd package to work differently
48+
}; // exporting a "default" would render the amd package to work differently
4949

5050

5151
var _default = {

src/basic-loader.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
function _load (tag) {
1+
const _load = (tag) => {
22
// attributes example: { 'data-test': 'new-attribute-here' }
3-
return function (url, attributes = {}) {
3+
return (url, attributes = {}) => {
44
// This promise will be used by Promise.all to determine success or failure
55
return new Promise((resolve, reject) => {
66
const element = document.createElement(tag);
@@ -23,18 +23,17 @@ function _load (tag) {
2323
parent = 'head';
2424
}
2525

26-
// Inject into document to kick off loading
2726
element[attr] = url;
28-
Object.keys(attributes).forEach(key => {
29-
element.setAttribute(key, attributes[key]);
30-
});
27+
Object.keys(attributes).forEach((name) => element.setAttribute(name, attributes[name]));
28+
29+
// Inject into document to kick off loading
3130
document[parent].appendChild(element);
3231
});
3332
};
34-
}
33+
};
3534

3635
export default {
3736
css: _load('link'),
3837
js: _load('script'),
39-
img: _load('img')
38+
img: _load('img'),
4039
};

0 commit comments

Comments
 (0)