Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Takes an argument and if it's an array, returns the first item in the array,
  3. * otherwise returns the argument. Used for Preact compatibility.
  4. */
  5. export var unwrapArray = function unwrapArray(arg) {
  6. return Array.isArray(arg) ? arg[0] : arg;
  7. };
  8. /**
  9. * Takes a maybe-undefined function and arbitrary args and invokes the function
  10. * only if it is defined.
  11. */
  12. export var safeInvoke = function safeInvoke(fn) {
  13. if (typeof fn === "function") {
  14. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  15. args[_key - 1] = arguments[_key];
  16. }
  17. return fn.apply(void 0, args);
  18. }
  19. };
  20. /**
  21. * Does a shallow equality check of two objects by comparing the reference
  22. * equality of each value.
  23. */
  24. export var shallowEqual = function shallowEqual(objA, objB) {
  25. var aKeys = Object.keys(objA);
  26. var bKeys = Object.keys(objB);
  27. if (bKeys.length !== aKeys.length) {
  28. return false;
  29. }
  30. for (var i = 0; i < bKeys.length; i++) {
  31. var key = aKeys[i];
  32. if (objA[key] !== objB[key]) {
  33. return false;
  34. }
  35. }
  36. return true;
  37. };
  38. /**
  39. * Sets a ref using either a ref callback or a ref object
  40. */
  41. export var setRef = function setRef(ref, node) {
  42. // if its a function call it
  43. if (typeof ref === "function") {
  44. return safeInvoke(ref, node);
  45. } // otherwise we should treat it as a ref object
  46. else if (ref != null) {
  47. ref.current = node;
  48. }
  49. };