Browse code

Refactor and rewrite as contao bundle

Benjamin Roth authored on04/11/2022 22:32:32
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,51 @@
1
+import { paramsList } from './params-list';
2
+import { isObject } from './utils';
3
+
4
+function getChangedParams(swiperParams, oldParams, children, oldChildren) {
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 oldChildrenKeys = oldChildren.map(function (child) {
13
+    return child.props && child.props.key;
14
+  });
15
+  var childrenKeys = children.map(function (child) {
16
+    return child.props && child.props.key;
17
+  });
18
+  if (oldChildrenKeys.join('') !== childrenKeys.join('')) keys.push('children');
19
+  if (oldChildren.length !== children.length) keys.push('children');
20
+  var watchParams = paramsList.filter(function (key) {
21
+    return key[0] === '_';
22
+  }).map(function (key) {
23
+    return key.replace(/_/, '');
24
+  });
25
+  watchParams.forEach(function (key) {
26
+    if (key in swiperParams && key in oldParams) {
27
+      if (isObject(swiperParams[key]) && isObject(oldParams[key])) {
28
+        var newKeys = Object.keys(swiperParams[key]);
29
+        var oldKeys = Object.keys(oldParams[key]);
30
+
31
+        if (newKeys.length !== oldKeys.length) {
32
+          addKey(key);
33
+        } else {
34
+          newKeys.forEach(function (newKey) {
35
+            if (swiperParams[key][newKey] !== oldParams[key][newKey]) {
36
+              addKey(key);
37
+            }
38
+          });
39
+          oldKeys.forEach(function (oldKey) {
40
+            if (swiperParams[key][oldKey] !== oldParams[key][oldKey]) addKey(key);
41
+          });
42
+        }
43
+      } else if (swiperParams[key] !== oldParams[key]) {
44
+        addKey(key);
45
+      }
46
+    }
47
+  });
48
+  return keys;
49
+}
50
+
51
+export { getChangedParams };
0 52
\ No newline at end of file