diff --git a/src/platforms/weex/runtime/modules/class.js b/src/platforms/weex/runtime/modules/class.js index 029b9e9e..47620552 100755 --- a/src/platforms/weex/runtime/modules/class.js +++ b/src/platforms/weex/runtime/modules/class.js @@ -1,6 +1,6 @@ /* @flow */ -import { extend } from 'shared/util' +import { extend, isObject } from 'shared/util' function updateClass (oldVnode: VNodeWithData, vnode: VNodeWithData) { const el = vnode.elm @@ -15,25 +15,8 @@ function updateClass (oldVnode: VNodeWithData, vnode: VNodeWithData) { return } - const oldClassList = [] - // unlike web, weex vnode staticClass is an Array - const oldStaticClass: any = oldData.staticClass - if (oldStaticClass) { - oldClassList.push.apply(oldClassList, oldStaticClass) - } - if (oldData.class) { - oldClassList.push.apply(oldClassList, oldData.class) - } - - const classList = [] - // unlike web, weex vnode staticClass is an Array - const staticClass: any = data.staticClass - if (staticClass) { - classList.push.apply(classList, staticClass) - } - if (data.class) { - classList.push.apply(classList, data.class) - } + const oldClassList = makeClassList(oldData) + const classList = makeClassList(data) if (typeof el.setClassList === 'function') { el.setClassList(classList) @@ -49,6 +32,22 @@ function updateClass (oldVnode: VNodeWithData, vnode: VNodeWithData) { } } +function makeClassList (data: VNodeData): Array { + const classList = [] + // unlike web, weex vnode staticClass is an Array + const staticClass: any = data.staticClass + const dataClass = data.class + if (staticClass) { + classList.push.apply(classList, staticClass) + } + if (Array.isArray(dataClass)) { + classList.push.apply(classList, dataClass) + } else if (isObject(dataClass)) { + classList.push.apply(classList, Object.keys(dataClass).filter(className => dataClass[className])) + } + return classList +} + function getStyle (oldClassList: Array, classList: Array, ctx: Component): Object { // style is a weex-only injected object // compiled from + + \ No newline at end of file