UNPKG

1.72 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.getChangedParams = getChangedParams;
5
6var _paramsList = require("./params-list");
7
8var _utils = require("./utils");
9
10function getChangedParams(swiperParams, oldParams, children, oldChildren) {
11 var keys = [];
12 if (!oldParams) return keys;
13
14 var addKey = function addKey(key) {
15 if (keys.indexOf(key) < 0) keys.push(key);
16 };
17
18 var oldChildrenKeys = oldChildren.map(function (child) {
19 return child.props && child.props.key;
20 });
21 var childrenKeys = children.map(function (child) {
22 return child.props && child.props.key;
23 });
24 if (oldChildrenKeys.join('') !== childrenKeys.join('')) keys.push('children');
25 if (oldChildren.length !== children.length) keys.push('children');
26
27 var watchParams = _paramsList.paramsList.filter(function (key) {
28 return key[0] === '_';
29 }).map(function (key) {
30 return key.replace(/_/, '');
31 });
32
33 watchParams.forEach(function (key) {
34 if (key in swiperParams && key in oldParams) {
35 if ((0, _utils.isObject)(swiperParams[key]) && (0, _utils.isObject)(oldParams[key])) {
36 var newKeys = Object.keys(swiperParams[key]);
37 var oldKeys = Object.keys(oldParams[key]);
38
39 if (newKeys.length !== oldKeys.length) {
40 addKey(key);
41 } else {
42 newKeys.forEach(function (newKey) {
43 if (swiperParams[key][newKey] !== oldParams[key][newKey]) {
44 addKey(key);
45 }
46 });
47 oldKeys.forEach(function (oldKey) {
48 if (swiperParams[key][oldKey] !== oldParams[key][oldKey]) addKey(key);
49 });
50 }
51 } else if (swiperParams[key] !== oldParams[key]) {
52 addKey(key);
53 }
54 }
55 });
56 return keys;
57}
\No newline at end of file