Skip to content

Commit

Permalink
Extract selector parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
vovkasm committed Dec 20, 2016
1 parent d328516 commit 2076355
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/stylesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ class SimpleSelector {
}
}

function parseSelector (value) {
let s
if (value.indexOf(' ') === -1) {
s = new SimpleSelector(value)
} else {
s = new Selector(value)
}
return s
}

class Rule {
constructor (selector, props, rank) {
this.selector = selector
Expand Down Expand Up @@ -153,12 +163,7 @@ class Stylesheet {
this._addRule(selector, props, 1)
}
_addRule (selectorValue, props, rank) {
let selector
if (selectorValue.indexOf(' ') === -1) {
selector = new SimpleSelector(selectorValue)
} else {
selector = new Selector(selectorValue)
}
const selector = parseSelector(selectorValue)
const rule = new Rule(selector, props, rank)
const key = rule.getKey()
if (this.rules[key] === undefined) {
Expand Down

0 comments on commit 2076355

Please sign in to comment.