UNPKG

1.49 kBJavaScriptView Raw
1import { paramsList } from './params-list.js';
2import { isObject } from './utils.js';
3
4function getChangedParams(swiperParams, oldParams, children, oldChildren, getKey) {
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 if (children && oldChildren) {
13 const oldChildrenKeys = oldChildren.map(getKey);
14 const childrenKeys = children.map(getKey);
15 if (oldChildrenKeys.join('') !== childrenKeys.join('')) addKey('children');
16 if (oldChildren.length !== children.length) addKey('children');
17 }
18
19 const watchParams = paramsList.filter(key => key[0] === '_').map(key => key.replace(/_/, ''));
20 watchParams.forEach(key => {
21 if (key in swiperParams && key in oldParams) {
22 if (isObject(swiperParams[key]) && isObject(oldParams[key])) {
23 const newKeys = Object.keys(swiperParams[key]);
24 const oldKeys = Object.keys(oldParams[key]);
25
26 if (newKeys.length !== oldKeys.length) {
27 addKey(key);
28 } else {
29 newKeys.forEach(newKey => {
30 if (swiperParams[key][newKey] !== oldParams[key][newKey]) {
31 addKey(key);
32 }
33 });
34 oldKeys.forEach(oldKey => {
35 if (swiperParams[key][oldKey] !== oldParams[key][oldKey]) addKey(key);
36 });
37 }
38 } else if (swiperParams[key] !== oldParams[key]) {
39 addKey(key);
40 }
41 }
42 });
43 return keys;
44}
45
46export { getChangedParams };
\No newline at end of file