Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

117 řádky
2.9 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.toArrayChildren = toArrayChildren;
  6. exports.findChildInChildrenByKey = findChildInChildrenByKey;
  7. exports.findShownChildInChildrenByKey = findShownChildInChildrenByKey;
  8. exports.findHiddenChildInChildrenByKey = findHiddenChildInChildrenByKey;
  9. exports.isSameChildren = isSameChildren;
  10. exports.mergeChildren = mergeChildren;
  11. var _react = require('react');
  12. var _react2 = _interopRequireDefault(_react);
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  14. function toArrayChildren(children) {
  15. var ret = [];
  16. _react2['default'].Children.forEach(children, function (child) {
  17. ret.push(child);
  18. });
  19. return ret;
  20. }
  21. function findChildInChildrenByKey(children, key) {
  22. var ret = null;
  23. if (children) {
  24. children.forEach(function (child) {
  25. if (ret) {
  26. return;
  27. }
  28. if (child && child.key === key) {
  29. ret = child;
  30. }
  31. });
  32. }
  33. return ret;
  34. }
  35. function findShownChildInChildrenByKey(children, key, showProp) {
  36. var ret = null;
  37. if (children) {
  38. children.forEach(function (child) {
  39. if (child && child.key === key && child.props[showProp]) {
  40. if (ret) {
  41. throw new Error('two child with same key for <rc-animate> children');
  42. }
  43. ret = child;
  44. }
  45. });
  46. }
  47. return ret;
  48. }
  49. function findHiddenChildInChildrenByKey(children, key, showProp) {
  50. var found = 0;
  51. if (children) {
  52. children.forEach(function (child) {
  53. if (found) {
  54. return;
  55. }
  56. found = child && child.key === key && !child.props[showProp];
  57. });
  58. }
  59. return found;
  60. }
  61. function isSameChildren(c1, c2, showProp) {
  62. var same = c1.length === c2.length;
  63. if (same) {
  64. c1.forEach(function (child, index) {
  65. var child2 = c2[index];
  66. if (child && child2) {
  67. if (child && !child2 || !child && child2) {
  68. same = false;
  69. } else if (child.key !== child2.key) {
  70. same = false;
  71. } else if (showProp && child.props[showProp] !== child2.props[showProp]) {
  72. same = false;
  73. }
  74. }
  75. });
  76. }
  77. return same;
  78. }
  79. function mergeChildren(prev, next) {
  80. var ret = [];
  81. // For each key of `next`, the list of keys to insert before that key in
  82. // the combined list
  83. var nextChildrenPending = {};
  84. var pendingChildren = [];
  85. prev.forEach(function (child) {
  86. if (child && findChildInChildrenByKey(next, child.key)) {
  87. if (pendingChildren.length) {
  88. nextChildrenPending[child.key] = pendingChildren;
  89. pendingChildren = [];
  90. }
  91. } else {
  92. pendingChildren.push(child);
  93. }
  94. });
  95. next.forEach(function (child) {
  96. if (child && Object.prototype.hasOwnProperty.call(nextChildrenPending, child.key)) {
  97. ret = ret.concat(nextChildrenPending[child.key]);
  98. }
  99. ret.push(child);
  100. });
  101. ret = ret.concat(pendingChildren);
  102. return ret;
  103. }