Skip to content

Commit de4899e

Browse files
committed
Merge pull request #15 from sirlancelot/patch-1
Always return the dispose function
2 parents 5e18452 + be4a763 commit de4899e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

addStyle.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module.exports = function addStyle(cssCode) {
66
if(typeof DEBUG !== "undefined" && DEBUG) {
77
if(typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment");
88
}
9-
var styleElement = document.createElement("style");
9+
var styleElement = document.createElement("style"),
10+
head = document.head || document.getElementsByTagName("head")[0];
1011
styleElement.type = "text/css";
11-
var head = document.getElementsByTagName("head")[0];
1212
head.appendChild(styleElement);
1313
if (styleElement.styleSheet) {
1414
styleElement.styleSheet.cssText = cssCode;
@@ -24,8 +24,15 @@ module.exports = function addStyle(cssCode) {
2424
styleElement.childNodes[0].nodeValue = cssCode;
2525
}
2626
} else {
27-
head.removeChild(styleElement);
27+
dispose();
2828
}
2929
};
30+
} else {
31+
// For the useable API, provide a function to remove the stylesheet.
32+
return dispose;
33+
}
34+
35+
function dispose() {
36+
head.removeChild(styleElement);
3037
}
3138
};

0 commit comments

Comments
 (0)