Guest User

Untitled

a guest
Nov 18th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. export function createElement(type, config, ...children) {
  2. var propName;
  3.  
  4. // Reserved names are extracted
  5. var props = {};
  6.  
  7. var key = null;
  8. var ref = null;
  9. var self = null;
  10. var source = null;
  11.  
  12. if (config != null) {
  13. if (hasValidRef(config)) {
  14. ref = config.ref;
  15. }
  16. if (hasValidKey(config)) {
  17. key = '' + config.key;
  18. }
  19.  
  20. self = config.__self === undefined ? null : config.__self;
  21. source = config.__source === undefined ? null : config.__source;
  22. // Remaining properties are added to a new props object
  23. for (propName in config) {
  24. if (
  25. hasOwnProperty.call(config, propName) &&
  26. !RESERVED_PROPS.hasOwnProperty(propName)
  27. ) {
  28. props[propName] = config[propName];
  29. }
  30. }
  31. }
  32.  
  33. // Children can be more than one argument, and those are transferred onto
  34. // the newly allocated props object.
  35. var childrenLength = children.length;
  36. if (childrenLength === 1) {
  37. props.children = children[0];
  38. } else if (childrenLength > 1) {
  39. props.children = children;
  40. }
  41.  
  42. // Resolve default props
  43. if (type && type.defaultProps) {
  44. var defaultProps = type.defaultProps;
  45. for (propName in defaultProps) {
  46. if (props[propName] === undefined) {
  47. props[propName] = defaultProps[propName];
  48. }
  49. }
  50. }
  51. if (__DEV__) {
  52. if (key || ref) {
  53. if (
  54. typeof props.$$typeof === 'undefined' ||
  55. props.$$typeof !== REACT_ELEMENT_TYPE
  56. ) {
  57. var displayName =
  58. typeof type === 'function'
  59. ? type.displayName || type.name || 'Unknown'
  60. : type;
  61. if (key) {
  62. defineKeyPropWarningGetter(props, displayName);
  63. }
  64. if (ref) {
  65. defineRefPropWarningGetter(props, displayName);
  66. }
  67. }
  68. }
  69. }
  70. return ReactElement(
  71. type,
  72. key,
  73. ref,
  74. self,
  75. source,
  76. ReactCurrentOwner.current,
  77. props,
  78. );
  79. }
Add Comment
Please, Sign In to add comment