|
1 | 1 | /* @flow */ |
2 | 2 |
|
3 | | -import { cached, extend, camelize, toObject } from 'shared/util' |
| 3 | +import { cached, camelize, extend, looseEqual } from 'shared/util' |
| 4 | +import { normalizeBindingStyle, getStyle } from 'web/util/style' |
4 | 5 |
|
5 | 6 | const cssVarRE = /^--/ |
6 | 7 | const setProp = (el, name, val) => { |
@@ -31,45 +32,39 @@ const normalize = cached(function (prop) { |
31 | 32 | }) |
32 | 33 |
|
33 | 34 | function updateStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) { |
34 | | - if ((!oldVnode.data || !oldVnode.data.style) && !vnode.data.style) { |
| 35 | + const data = vnode.data |
| 36 | + const oldData = oldVnode.data |
| 37 | + |
| 38 | + if (!data.staticStyle && !data.style && |
| 39 | + !oldData.staticStyle && !oldData.style) { |
35 | 40 | return |
36 | 41 | } |
| 42 | + |
37 | 43 | let cur, name |
38 | 44 | const el: any = vnode.elm |
39 | 45 | const oldStyle: any = oldVnode.data.style || {} |
40 | | - let style: any = vnode.data.style || {} |
41 | | - |
42 | | - // handle string |
43 | | - if (typeof style === 'string') { |
44 | | - el.style.cssText = style |
45 | | - return |
46 | | - } |
47 | | - |
48 | | - const needClone = style.__ob__ |
| 46 | + const style: Object = normalizeBindingStyle(vnode.data.style || {}) |
| 47 | + vnode.data.style = extend({}, style) |
49 | 48 |
|
50 | | - // handle array syntax |
51 | | - if (Array.isArray(style)) { |
52 | | - style = vnode.data.style = toObject(style) |
53 | | - } |
| 49 | + const newStyle: Object = getStyle(vnode, true) |
54 | 50 |
|
55 | | - // clone the style for future updates, |
56 | | - // in case the user mutates the style object in-place. |
57 | | - if (needClone) { |
58 | | - style = vnode.data.style = extend({}, style) |
| 51 | + if (looseEqual(el._prevStyle, newStyle)) { |
| 52 | + return |
59 | 53 | } |
60 | 54 |
|
61 | 55 | for (name in oldStyle) { |
62 | | - if (style[name] == null) { |
| 56 | + if (newStyle[name] == null) { |
63 | 57 | setProp(el, name, '') |
64 | 58 | } |
65 | 59 | } |
66 | | - for (name in style) { |
67 | | - cur = style[name] |
| 60 | + for (name in newStyle) { |
| 61 | + cur = newStyle[name] |
68 | 62 | if (cur !== oldStyle[name]) { |
69 | 63 | // ie9 setting to null has no effect, must use empty string |
70 | 64 | setProp(el, name, cur == null ? '' : cur) |
71 | 65 | } |
72 | 66 | } |
| 67 | + el._prevStyle = newStyle |
73 | 68 | } |
74 | 69 |
|
75 | 70 | export default { |
|
0 commit comments