Skip to content

Commit 5339426

Browse files
committed
optimize class rendering
1 parent 9084e85 commit 5339426

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

src/platforms/web/util/class.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import { isDef, isUndef, isObject } from 'shared/util'
3+
import { isDef, isObject } from 'shared/util'
44

55
export function genClassForVnode (vnode: VNode): string {
66
let data = vnode.data
@@ -48,31 +48,38 @@ export function concat (a: ?string, b: ?string): string {
4848
}
4949

5050
export function stringifyClass (value: any): string {
51-
if (isUndef(value)) {
52-
return ''
51+
if (Array.isArray(value)) {
52+
return stringifyArray(value)
53+
}
54+
if (isObject(value)) {
55+
return stringifyObject(value)
5356
}
5457
if (typeof value === 'string') {
5558
return value
5659
}
60+
/* istanbul ignore next */
61+
return ''
62+
}
63+
64+
function stringifyArray (value: Array<any>): string {
5765
let res = ''
58-
if (Array.isArray(value)) {
59-
let stringified
60-
for (let i = 0, l = value.length; i < l; i++) {
61-
if (isDef(value[i])) {
62-
if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') {
63-
res += stringified + ' '
64-
}
65-
}
66+
let stringified
67+
for (let i = 0, l = value.length; i < l; i++) {
68+
if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') {
69+
if (res) res += ' '
70+
res += stringified
6671
}
67-
return res.slice(0, -1)
6872
}
69-
if (isObject(value)) {
70-
for (const key in value) {
73+
return res
74+
}
75+
76+
function stringifyObject (value: Object): string {
77+
let res = ''
78+
for (const key in value) {
79+
if (value[key]) {
7180
if (res) res += ' '
72-
if (value[key]) res += key
81+
res += key
7382
}
74-
return res
7583
}
76-
/* istanbul ignore next */
7784
return res
7885
}

0 commit comments

Comments
 (0)