Skip to content
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

refactor(class-util): cache whitespace regex #8743

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/platforms/web/runtime/class-util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* @flow */

const whitespaceRE = /\s+/

/**
* Add class with compatibility for SVG since classList is not supported on
* SVG elements in IE
Expand All @@ -13,7 +15,7 @@ export function addClass (el: HTMLElement, cls: ?string) {
/* istanbul ignore else */
if (el.classList) {
if (cls.indexOf(' ') > -1) {
cls.split(/\s+/).forEach(c => el.classList.add(c))
cls.split(whitespaceRE).forEach(c => el.classList.add(c))
} else {
el.classList.add(cls)
}
Expand All @@ -38,7 +40,7 @@ export function removeClass (el: HTMLElement, cls: ?string) {
/* istanbul ignore else */
if (el.classList) {
if (cls.indexOf(' ') > -1) {
cls.split(/\s+/).forEach(c => el.classList.remove(c))
cls.split(whitespaceRE).forEach(c => el.classList.remove(c))
} else {
el.classList.remove(cls)
}
Expand Down