Skip to content

Commit 489892b

Browse files
authored
remove phantom stuff (#3782)
* remove phantom stuff * lint fix * use deep clone
1 parent 3f89d17 commit 489892b

1 file changed

Lines changed: 21 additions & 27 deletions

File tree

packages/less/src/less-browser/index.js

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import ErrorReporting from './error-reporting';
1212
import Cache from './cache';
1313
import ImageSize from './image-size';
1414

15+
/**
16+
* @param {Window} window
17+
* @param {Object} options
18+
*/
1519
export default (window, options) => {
1620
const document = window.document;
1721
const less = lessRoot();
@@ -46,42 +50,32 @@ export default (window, options) => {
4650
return cloned;
4751
}
4852

49-
// only really needed for phantom
50-
function bind(func, thisArg) {
51-
const curryArgs = Array.prototype.slice.call(arguments, 2);
52-
return function() {
53-
const args = curryArgs.concat(Array.prototype.slice.call(arguments, 0));
54-
return func.apply(thisArg, args);
55-
};
56-
}
57-
5853
function loadStyles(modifyVars) {
5954
const styles = document.getElementsByTagName('style');
60-
let style;
6155

62-
for (let i = 0; i < styles.length; i++) {
63-
style = styles[i];
56+
for (let style of styles) {
6457
if (style.type.match(typePattern)) {
65-
const instanceOptions = clone(options);
66-
instanceOptions.modifyVars = modifyVars;
58+
const instanceOptions = {
59+
...clone(options),
60+
modifyVars,
61+
filename: document.location.href.replace(/#.*$/, '')
62+
}
63+
6764
const lessText = style.innerHTML || '';
68-
instanceOptions.filename = document.location.href.replace(/#.*$/, '');
6965

7066
/* jshint loopfunc:true */
71-
// use closure to store current style
72-
less.render(lessText, instanceOptions,
73-
bind((style, e, result) => {
74-
if (e) {
75-
errors.add(e, 'inline');
67+
less.render(lessText, instanceOptions, (err, result) => {
68+
if (err) {
69+
errors.add(err, 'inline');
70+
} else {
71+
style.type = 'text/css';
72+
if (style.styleSheet) {
73+
style.styleSheet.cssText = result.css;
7674
} else {
77-
style.type = 'text/css';
78-
if (style.styleSheet) {
79-
style.styleSheet.cssText = result.css;
80-
} else {
81-
style.innerHTML = result.css;
82-
}
75+
style.innerHTML = result.css;
8376
}
84-
}, null, style));
77+
}
78+
});
8579
}
8680
}
8781
}

0 commit comments

Comments
 (0)