Skip to content

Commit 6d25e55

Browse files
committed
feat: 🎸 add .del() to VRule, removeRule() now acc only 1 arg
1 parent 6213e49 commit 6d25e55

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

‎addon/vcssom.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ exports.addon = function (renderer) {
2828
style.setProperty(kebab(property), newDecl[property]);
2929
this.decl = newDecl;
3030
};
31+
VRule.prototype.del = function () {
32+
removeRule(this.rule);
33+
};
3134

3235
function VSheet () {
3336
/**
@@ -42,17 +45,14 @@ exports.addon = function (renderer) {
4245
this.tree = {};
4346
}
4447
VSheet.prototype.diff = function (newTree) {
45-
var sh = renderer.sh.sheet;
46-
var msh = renderer.msh.sheet;
4748
var oldTree = this.tree;
4849

4950
// Remove media queries not present in new tree.
5051
for (var prelude in oldTree) {
5152
if (newTree[prelude] === undefined) {
5253
var rules = oldTree[prelude];
53-
for (var selector in rules) {
54-
removeRule(msh, rules[selector]);
55-
}
54+
for (var selector in rules)
55+
rules[selector].del();
5656
}
5757
}
5858

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

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

95-
renderer.VSheet = VSheet
95+
renderer.VRule = VRule;
96+
renderer.VSheet = VSheet;
9697
};

‎addon/vcssom/removeRule.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// TODO: `rule` should have a reference to stylesheet it is contained in,
22
// maybe we don't need to pass `sh` in here.
3-
function removeRule (sh, rule) {
3+
function removeRule (rule) {
44
var maxIndex = rule.index;
5+
var sh = rule.parentStyleSheet;
6+
console.log('sh', sh, rule);
57
var rules = sh.cssRules || sh.rules;
68
maxIndex = Math.max(maxIndex, rules.length - 1);
79
while (maxIndex >= 0) {

0 commit comments

Comments
 (0)