Skip to content

Commit

Permalink
feat: 🎸 add .del() to VRule, removeRule() now acc only 1 arg
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 26, 2019
1 parent 6213e49 commit 6d25e55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 8 additions & 7 deletions addon/vcssom.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ exports.addon = function (renderer) {
style.setProperty(kebab(property), newDecl[property]);
this.decl = newDecl;
};
VRule.prototype.del = function () {
removeRule(this.rule);
};

function VSheet () {
/**
Expand All @@ -42,17 +45,14 @@ exports.addon = function (renderer) {
this.tree = {};
}
VSheet.prototype.diff = function (newTree) {
var sh = renderer.sh.sheet;
var msh = renderer.msh.sheet;
var oldTree = this.tree;

// Remove media queries not present in new tree.
for (var prelude in oldTree) {
if (newTree[prelude] === undefined) {
var rules = oldTree[prelude];
for (var selector in rules) {
removeRule(msh, rules[selector]);
}
for (var selector in rules)
rules[selector].del();
}
}

Expand All @@ -72,7 +72,7 @@ exports.addon = function (renderer) {
// Remove rules not present in new tree.
for (var selector in oldRules)
if (!newRules[selector])
deleteRule(sh, oldRules[selector]);
oldRules[selector].del();

// Apply new rules.
for (var selector in newRules) {
Expand All @@ -92,5 +92,6 @@ exports.addon = function (renderer) {
this.tree = newTree;
};

renderer.VSheet = VSheet
renderer.VRule = VRule;
renderer.VSheet = VSheet;
};
4 changes: 3 additions & 1 deletion addon/vcssom/removeRule.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// TODO: `rule` should have a reference to stylesheet it is contained in,
// maybe we don't need to pass `sh` in here.
function removeRule (sh, rule) {
function removeRule (rule) {
var maxIndex = rule.index;
var sh = rule.parentStyleSheet;
console.log('sh', sh, rule);
var rules = sh.cssRules || sh.rules;
maxIndex = Math.max(maxIndex, rules.length - 1);
while (maxIndex >= 0) {
Expand Down

0 comments on commit 6d25e55

Please sign in to comment.