UNPKG

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