1 | import { isObject } from './utils';
|
2 | import { paramsList } from './params-list';
|
3 |
|
4 | function getChangedParams(swiperParams, oldParams) {
|
5 | var keys = [];
|
6 | if (!oldParams) return keys;
|
7 |
|
8 | var addKey = function addKey(key) {
|
9 | if (keys.indexOf(key) < 0) keys.push(key);
|
10 | };
|
11 |
|
12 | var watchParams = paramsList.filter(function (key) {
|
13 | return key[0] === '_';
|
14 | }).map(function (key) {
|
15 | return key.replace(/_/, '');
|
16 | });
|
17 | watchParams.forEach(function (key) {
|
18 | if (key in swiperParams && key in oldParams) {
|
19 | if (isObject(swiperParams[key]) && isObject(oldParams[key])) {
|
20 | var newKeys = Object.keys(swiperParams[key]);
|
21 | var oldKeys = Object.keys(oldParams[key]);
|
22 |
|
23 | if (newKeys.length !== oldKeys.length) {
|
24 | addKey(key);
|
25 | } else {
|
26 | newKeys.forEach(function (newKey) {
|
27 | if (swiperParams[key][newKey] !== oldParams[key][newKey]) {
|
28 | addKey(key);
|
29 | }
|
30 | });
|
31 | oldKeys.forEach(function (oldKey) {
|
32 | if (swiperParams[key][oldKey] !== oldParams[key][oldKey]) addKey(key);
|
33 | });
|
34 | }
|
35 | } else if (swiperParams[key] !== oldParams[key]) {
|
36 | addKey(key);
|
37 | }
|
38 | }
|
39 | });
|
40 | return keys;
|
41 | }
|
42 |
|
43 | export { getChangedParams }; |
\ | No newline at end of file |