Skip to content

Commit 621756e

Browse files
committed
use more efficient deep update handling for dom modules
1 parent 6fac625 commit 621756e

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/platforms/web/runtime/modules/attrs.js

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

3+
import { extend } from 'shared/util'
34
import {
45
isBooleanAttr,
56
isEnumeratedAttr,
@@ -16,11 +17,14 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) {
1617
let key, cur, old
1718
const elm = vnode.elm
1819
const oldAttrs = oldVnode.data.attrs || {}
19-
const attrs = vnode.data.attrs || {}
20-
const clonedAttrs = vnode.data.attrs = {}
20+
let attrs = vnode.data.attrs || {}
21+
// clone observed objects, as the user probably wants to mutate it
22+
if (attrs.__ob__) {
23+
attrs = vnode.data.attrs = extend({}, attrs)
24+
}
2125

2226
for (key in attrs) {
23-
cur = clonedAttrs[key] = attrs[key]
27+
cur = attrs[key]
2428
old = oldAttrs[key]
2529
if (old !== cur) {
2630
setAttr(elm, key, cur)

src/platforms/web/runtime/modules/dom-props.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
/* @flow */
22

3+
import { extend } from 'shared/util'
4+
35
function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
46
if (!oldVnode.data.domProps && !vnode.data.domProps) {
57
return
68
}
79
let key, cur
810
const elm: any = vnode.elm
911
const oldProps = oldVnode.data.domProps || {}
10-
const props = vnode.data.domProps || {}
11-
const clonedProps = vnode.data.domProps = {}
12+
let props = vnode.data.domProps || {}
13+
// clone observed objects, as the user probably wants to mutate it
14+
if (props.__ob__) {
15+
props = vnode.data.domProps = extend({}, props)
16+
}
1217

1318
for (key in oldProps) {
1419
if (props[key] == null) {
1520
elm[key] = undefined
1621
}
1722
}
1823
for (key in props) {
19-
cur = clonedProps[key] = props[key]
24+
cur = props[key]
2025
if (key === 'value') {
2126
// store value as _value as well since
2227
// non-string values will be stringified

src/platforms/web/runtime/modules/style.js

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

3-
import { cached, camelize, toObject } from 'shared/util'
3+
import { cached, extend, camelize, toObject } from 'shared/util'
44

55
const prefixes = ['Webkit', 'Moz', 'ms']
66

@@ -28,23 +28,26 @@ function updateStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) {
2828
const elm: any = vnode.elm
2929
const oldStyle: any = oldVnode.data.style || {}
3030
let style = vnode.data.style || {}
31+
const needClone = style.__ob__
3132

3233
// handle array syntax
3334
if (Array.isArray(style)) {
34-
style = toObject(style)
35+
style = vnode.data.style = toObject(style)
3536
}
3637

3738
// clone the style for future updates,
3839
// in case the user mutates the style object in-place.
39-
const clonedStyle = vnode.data.style = {}
40+
if (needClone) {
41+
style = vnode.data.style = extend({}, style)
42+
}
4043

4144
for (name in oldStyle) {
4245
if (!style[name]) {
4346
elm.style[normalize(name)] = ''
4447
}
4548
}
4649
for (name in style) {
47-
cur = clonedStyle[name] = style[name]
50+
cur = style[name]
4851
if (cur !== oldStyle[name]) {
4952
// ie9 setting to null has no effect, must use empty string
5053
elm.style[normalize(name)] = cur || ''

0 commit comments

Comments
 (0)