-
Notifications
You must be signed in to change notification settings - Fork 31
/
diff.js
32 lines (25 loc) · 858 Bytes
/
diff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import {diff} from 'deep-object-diff';
import flatten from './flatten';
export default function(newData) {
if (
newData == null ||
Object.prototype.toString.call(newData) !== '[object Object]'
) {
console.warn('参数错误,data必须为object类型');
return false;
}
if (this == null || this.data == null) {
console.warn('请绑定diff函数到Page/Component实例!');
return false;
};
// filter data without __webviewId__ from this.data
let oldData = Object.keys(newData).reduce((prev, key)=>{
if (key === '__webviewId__') return prev;
if (this.data.hasOwnProperty(key)) {
prev[key] = this.data[key];
};
return prev;
}, {});
let diffValue = diff(oldData, newData);
return flatten(oldData, newData, diffValue);
}