packages/proact/vdom/component.js
function from(renderFn, name = renderFn.name) {
  if (typeof name === 'function') {
    [renderFn, name] = [name, renderFn];
  } else if (typeof renderFn !== 'function') {
    throw InvalidArgType({ renderFn }, 'a function');
  }

  name = String(name);
  if (!name) {
    throw InvalidArgValue({ name }, 'should not be empty');
  }

  function RenderFunction(...args) {
    if (!new.target) return new RenderFunction(...args);

    // 1st argument may be constructor itself to (redundantly) capture identity.
    if (args[0] === RenderFunction) args.shift();

    // Delegate processing of properties to Node.
    apply(Node, this, args);
  }

  // The isViewComponent, toStringTag, and provideContext properties are the
  // same for all render function components and could thus be moved into a
  // shared prototype. While that may reduce memory pressure, it also increases
  // the length of the prototype chain and thus property lookup latency.
  const RenderFunctionPrototype = create(NodePrototype, {
    constructor: { configurable, value: RenderFunction },
    isViewComponent: { configurable, value: true }, // Flag to detect view component type.
    [toStringTag]: { configurable, value: 'Proact.Component' },
    name: { configurable, enumerable, value: name },
    render: { configurable, value: renderFn },
    provideContext: { configurable, value: provideContext },
  });

  defineProperties(RenderFunction, {
    prototype: { value: RenderFunctionPrototype },
    name: { configurable, enumerable, value: name },
  });

  return RenderFunction;
}
function from(renderFn, name = renderFn.name) {
  if (typeof name === 'function') {
    [renderFn, name] = [name, renderFn];
  } else if (typeof renderFn !== 'function') {
    throw InvalidArgType({ renderFn }, 'a function');
  }

  name = String(name);
  if (!name) {
    throw InvalidArgValue({ name }, 'should not be empty');
  }

  function RenderFunction(...args) {
    if (!new.target) return new RenderFunction(...args);

    // 1st argument may be constructor itself to (redundantly) capture identity.
    if (args[0] === RenderFunction) args.shift();

    // Delegate processing of properties to Node.
    apply(Node, this, args);
  }

  // The isViewComponent, toStringTag, and provideContext properties are the
  // same for all render function components and could thus be moved into a
  // shared prototype. While that may reduce memory pressure, it also increases
  // the length of the prototype chain and thus property lookup latency.
  const RenderFunctionPrototype = create(NodePrototype, {
    constructor: { configurable, value: RenderFunction },
    isViewComponent: { configurable, value: true }, // Flag to detect view component type.
    [toStringTag]: { configurable, value: 'Proact.Component' },
    name: { configurable, enumerable, value: name },
    render: { configurable, value: renderFn },
    provideContext: { configurable, value: provideContext },
  });

  defineProperties(RenderFunction, {
    prototype: { value: RenderFunctionPrototype },
    name: { configurable, enumerable, value: name },
  });

  return RenderFunction;
}
function from ( renderFn , name = renderFn . name ) { if ( typeof name === 'function' ) { [ renderFn , name ] = [ name , renderFn ] ; } else if ( typeof renderFn !== 'function' ) { throw InvalidArgType ( { renderFn } , 'a function' ) ; } name = String ( name ) ; if ( ! name ) { throw InvalidArgValue ( { name } , 'should not be empty' ) ; } function RenderFunction ( ... args ) { if ( ! new . target ) return new RenderFunction ( ... args ) ; // 1st argument may be constructor itself to (redundantly) capture identity. if ( args [ 0 ] === RenderFunction ) args . shift ( ) ; // Delegate processing of properties to Node. apply ( Node , this , args ) ; } // The isViewComponent, toStringTag, and provideContext properties are the // same for all render function components and could thus be moved into a // shared prototype. While that may reduce memory pressure, it also increases // the length of the prototype chain and thus property lookup latency. const RenderFunctionPrototype = create ( NodePrototype , { constructor : { configurable , value : RenderFunction } , isViewComponent : { configurable , value : true } , // Flag to detect view component type. [ toStringTag ] : { configurable , value : 'Proact.Component' } , name : { configurable , enumerable , value : name } , render : { configurable , value : renderFn } , provideContext : { configurable , value : provideContext } , } ) ; defineProperties ( RenderFunction , { prototype : { value : RenderFunctionPrototype } , name : { configurable , enumerable , value : name } , } ) ; return RenderFunction ; }
Create a functional component with the given render function and name. For
named functions, the name may be omitted to avoid repetition. The name may
also be specified before the render function to accommodate arrow functions
while also optimizing for readability.
Create a functional component with the given render function and name . For named functions the name may be omitted to avoid repetition . The name may also be specified before the render function to accommodate arrow functions while also optimizing for readability .