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.
 
 
 
 

38 lines
1.3 KiB

  1. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  2. export function fillRef(ref, node) {
  3. if (typeof ref === 'function') {
  4. ref(node);
  5. } else if (_typeof(ref) === 'object' && ref && 'current' in ref) {
  6. ref.current = node;
  7. }
  8. }
  9. /**
  10. * Merge refs into one ref function to support ref passing.
  11. */
  12. export function composeRef() {
  13. for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
  14. refs[_key] = arguments[_key];
  15. }
  16. return function (node) {
  17. refs.forEach(function (ref) {
  18. fillRef(ref, node);
  19. });
  20. };
  21. }
  22. export function supportRef(nodeOrComponent) {
  23. // Function component node
  24. if (nodeOrComponent.type && nodeOrComponent.type.prototype && !nodeOrComponent.type.prototype.render) {
  25. return false;
  26. } // Class component
  27. if (typeof nodeOrComponent === 'function' && nodeOrComponent.prototype && !nodeOrComponent.prototype.render) {
  28. return false;
  29. }
  30. return true;
  31. }
  32. /* eslint-enable */