Skip to content

Commit

Permalink
new hot API
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Jul 18, 2018
1 parent 1de8c9b commit 4c48829
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
9 changes: 0 additions & 9 deletions packages/moon-mvl/lib/addCSS.js
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
module.exports = (code) => {
const head = document.querySelector("head");
const style = document.createElement("style");
style.appendChild(document.createTextNode(code));
head.appendChild(style);

return () => {
head.removeChild(style);
};
};
21 changes: 12 additions & 9 deletions packages/moon-mvl/lib/hot.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
let components = [];

module.exports.register = (component) => {
components.push(component);
module.exports.registerJS = (component) => {
return () => {
component.destroy();
};
};

module.exports.remove = () => {
for (let i = 0; i < components.length; i++) {
components[i].destroy();
}
module.exports.registerCSS = (code) => {
const head = document.querySelector("head");
const style = document.createElement("style");
style.appendChild(document.createTextNode(code));
head.appendChild(style);

components = [];
return () => {
head.removeChild(style);
};
};

0 comments on commit 4c48829

Please sign in to comment.