Skip to content

Add support for reading rules from imported CSS style sheet #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

fengdh
Copy link

@fengdh fengdh commented Apr 20, 2016

No description provided.

fengdh added 2 commits April 20, 2016 17:16
also rewrite readRules(..):
- potential bug when rules is plain String
- use switch/case instead of if..else if
}
break;
case 3: // CSSRule.IMPORT_RULE
r = r.styleSheet; // then continue to next case statement
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be this 'case' at the first position, right before case 1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're almost equivalent.

It is said that switch/case is more intuitive and easily optimized by JS engine. If count of conditions growing, switch/case usually runs faster than multiple if-else-if.

But position of case 3 and case 4 must not be exchanged, since no break at the end of case 3 which continuing to execute case 4.

@see http://archive.oreilly.com/pub/a/server-administration/excerpts/even-faster-websites/writing-efficient-javascript.html

Copy link
Owner

@marcj marcj May 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to understand, that's why I prefer not to have switch-case especially when they contain non breaking cases. It appears to me like it's wrong, because you overwrite r in case 3 because there is only case 4 that can react on that case. STYLE_RULE in case 1 is not able to check for that new r.

@fengdh fengdh changed the title Add support for read rules from imported CSS style sheet Add support for reading rules from imported CSS style sheet Apr 21, 2016
lucasconstantino added a commit to lucasconstantino/css-element-queries that referenced this pull request Jun 23, 2016
Basically took the idea on [pull-104](marcj#104) but made only the part that matters for this feature.
@marcj marcj closed this Dec 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants