get-changed-params.js 1.1 KB

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