aboutsummaryrefslogtreecommitdiff
path: root/node_modules/vue/src/platforms/weex/runtime/modules/class.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/vue/src/platforms/weex/runtime/modules/class.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/vue/src/platforms/weex/runtime/modules/class.js')
-rwxr-xr-xnode_modules/vue/src/platforms/weex/runtime/modules/class.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/node_modules/vue/src/platforms/weex/runtime/modules/class.js b/node_modules/vue/src/platforms/weex/runtime/modules/class.js
new file mode 100755
index 00000000..029b9e9e
--- /dev/null
+++ b/node_modules/vue/src/platforms/weex/runtime/modules/class.js
@@ -0,0 +1,75 @@
+/* @flow */
+
+import { extend } from 'shared/util'
+
+function updateClass (oldVnode: VNodeWithData, vnode: VNodeWithData) {
+ const el = vnode.elm
+ const ctx = vnode.context
+
+ const data: VNodeData = vnode.data
+ const oldData: VNodeData = oldVnode.data
+ if (!data.staticClass &&
+ !data.class &&
+ (!oldData || (!oldData.staticClass && !oldData.class))
+ ) {
+ 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)
+ }
+
+ if (typeof el.setClassList === 'function') {
+ el.setClassList(classList)
+ } else {
+ const style = getStyle(oldClassList, classList, ctx)
+ if (typeof el.setStyles === 'function') {
+ el.setStyles(style)
+ } else {
+ for (const key in style) {
+ el.setStyle(key, style[key])
+ }
+ }
+ }
+}
+
+function getStyle (oldClassList: Array<string>, classList: Array<string>, ctx: Component): Object {
+ // style is a weex-only injected object
+ // compiled from <style> tags in weex files
+ const stylesheet: any = ctx.$options.style || {}
+ const result = {}
+ classList.forEach(name => {
+ const style = stylesheet[name]
+ extend(result, style)
+ })
+ oldClassList.forEach(name => {
+ const style = stylesheet[name]
+ for (const key in style) {
+ if (!result.hasOwnProperty(key)) {
+ result[key] = ''
+ }
+ }
+ })
+ return result
+}
+
+export default {
+ create: updateClass,
+ update: updateClass
+}