UNPKG

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