How to use the inferno-shared.isFunction function in inferno-shared

To help you get started, we’ve selected a few inferno-shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github infernojs / inferno / packages / inferno-compat / src / index.ts View on Github external
options.createVNode = (vNode: VNode) => {
  const children = vNode.children as any;
  let props: any = vNode.props;

  if (isNullOrUndef(props)) {
    props = vNode.props = {};
  }

  // React supports iterable children, in addition to Array-like
  if (hasSymbolSupport && !isNull(children) && typeof children === 'object' && !isArray(children) && isFunction(children[symbolIterator])) {
    vNode.children = iterableToArray(children[symbolIterator]());
  }

  if (!isNullOrUndef(children) && isNullOrUndef(props.children)) {
    props.children = children;
  }
  if (vNode.flags & VNodeFlags.Component) {
    if (isString(vNode.type)) {
      vNode.flags = getFlagsForElementVnode(vNode.type as string);
      if (props) {
        normalizeProps(vNode);
      }
    }
  }

  const flags = vNode.flags;
github infernojs / inferno / packages / inferno-hydrate / src / index.ts View on Github external
// clear any other DOM nodes, there should be only a single entry for the root
    while (dom && (dom = dom.nextSibling as Element)) {
      parentDOM.removeChild(dom);
    }

    if (lifecycle.length > 0) {
      let listener;
      while ((listener = lifecycle.shift()) !== undefined) {
        listener();
      }
    }
  }

  (parentDOM as any).$V = input;

  if (isFunction(callback)) {
    callback();
  }
}
github infernojs / inferno / packages / inferno-server / src / renderToString.queuestream.ts View on Github external
if (pending) {
            const state = instance.state;

            if (state === null) {
              instance.state = pending;
            } else {
              for (const key in pending) {
                state[key] = pending[key];
              }
            }
            instance.$PS = null;
          }
          instance.$BR = false;
        }
        // Trigger extra promise-based lifecycle hook
        if (isFunction(instance.getInitialProps)) {
          const initialProps = instance.getInitialProps(instance.props, instance.context);
          if (initialProps) {
            if (Promise.resolve(initialProps) === initialProps) {
              const promisePosition = this.promises.push([]) - 1;
              this.addToQueue(
                initialProps.then(dataForContext => {
                  if (typeof dataForContext === 'object') {
                    instance.props = combineFrom(instance.props, dataForContext);
                  }

                  const renderOut = instance.render(instance.props, instance.state, instance.context);
                  if (isInvalid(renderOut)) {
                    this.addToQueue('', promisePosition);
                  } else if (isString(renderOut)) {
                    this.addToQueue(escapeText(renderOut), promisePosition);
                  } else if (isNumber(renderOut)) {
github infernojs / inferno / packages / inferno-server / src / renderToString.queuestream.ts View on Github external
const hasNewAPI = Boolean(type.getDerivedStateFromProps);
        instance.$BS = false;
        instance.$SSR = true;
        let childContext;
        if (!isUndefined(instance.getChildContext)) {
          childContext = instance.getChildContext();
        }
        if (!isNullOrUndef(childContext)) {
          context = combineFrom(context, childContext);
        }
        if (instance.props === EMPTY_OBJ) {
          instance.props = props;
        }
        instance.context = context;
        // Trigger lifecycle hook
        if (!hasNewAPI && isFunction(instance.componentWillMount)) {
          instance.$BR = true;
          instance.componentWillMount();
          const pending = instance.$PS;

          if (pending) {
            const state = instance.state;

            if (state === null) {
              instance.state = pending;
            } else {
              for (const key in pending) {
                state[key] = pending[key];
              }
            }
            instance.$PS = null;
          }
github infernojs / inferno / packages / inferno-server / src / renderToString.stream.ts View on Github external
if (isString(renderOutput)) {
        return this.push(escapeText(renderOutput));
      }
      if (isNumber(renderOutput)) {
        return this.push(renderOutput + '');
      }

      return this.renderNode(renderOutput, context);
    }

    const instance = new type(props, context);
    const hasNewAPI = Boolean(type.getDerivedStateFromProps);
    instance.$BS = false;
    instance.$SSR = true;
    let childContext;
    if (isFunction(instance.getChildContext)) {
      childContext = instance.getChildContext();
    }

    if (!isNullOrUndef(childContext)) {
      context = combineFrom(context, childContext);
    }
    instance.context = context;
    instance.$BR = true;

    return Promise.resolve(!hasNewAPI && instance.componentWillMount && instance.componentWillMount()).then(() => {
      const pending = instance.$PS;
      if (pending) {
        const state = instance.state;

        if (state === null) {
          instance.state = pending;
github infernojs / inferno / packages / inferno / src / DOM / events / attachEvent.ts View on Github external
export function attachEvent(dom, eventName, handler) {
  const previousKey = `$${eventName}`;
  const previousArgs = dom[previousKey];

  if (previousArgs) {
    if (previousArgs[1].wrapped) {
      return;
    }
    dom.removeEventListener(previousArgs[0], previousArgs[1]);
    dom[previousKey] = null;
  }

  if (isFunction(handler)) {
    dom.addEventListener(eventName, handler);
    dom[previousKey] = [eventName, handler];
  }
}
github jhsware / inferno-bootstrap / src / utils.js View on Github external
export function getTarget(target) {
  if (isFunction(target)) {
    return target();
  }

  if (typeof target === 'string' && document) {
    const selection = document.querySelector(target);
    if (selection === null) {
      return document.querySelector(`#${target}`);
    }
    return selection;
  }

  return target;
}
github infernojs / inferno / packages / inferno-server / src / renderToString.ts View on Github external
instance.$SSR = true;
      let childContext;
      if (isFunction(instance.getChildContext)) {
        childContext = instance.getChildContext();
      }

      if (isNullOrUndef(childContext)) {
        childContext = context;
      } else {
        childContext = combineFrom(context, childContext);
      }
      if (instance.props === EMPTY_OBJ) {
        instance.props = props;
      }
      instance.context = context;
      if (!hasNewAPI && isFunction(instance.componentWillMount)) {
        instance.$BR = true;
        instance.componentWillMount();
        instance.$BR = false;
        const pending = instance.$PS;

        if (pending) {
          const state = instance.state;

          if (state === null) {
            instance.state = pending;
          } else {
            for (const key in pending) {
              state[key] = pending[key];
            }
          }
          instance.$PSS = false;
github infernojs / inferno / packages / inferno-server / src / renderToString.ts View on Github external
function renderVNodeToString(vNode, parent, context): string {
  const flags = vNode.flags;
  const type = vNode.type;
  const props = vNode.props || EMPTY_OBJ;
  const children = vNode.children;

  if ((flags & VNodeFlags.Component) !== 0) {
    const isClass = flags & VNodeFlags.ComponentClass;

    if (isClass) {
      const instance = new type(props, context);
      const hasNewAPI = Boolean(type.getDerivedStateFromProps);
      instance.$BS = false;
      instance.$SSR = true;
      let childContext;
      if (isFunction(instance.getChildContext)) {
        childContext = instance.getChildContext();
      }

      if (isNullOrUndef(childContext)) {
        childContext = context;
      } else {
        childContext = combineFrom(context, childContext);
      }
      if (instance.props === EMPTY_OBJ) {
        instance.props = props;
      }
      instance.context = context;
      if (!hasNewAPI && isFunction(instance.componentWillMount)) {
        instance.$BR = true;
        instance.componentWillMount();
        instance.$BR = false;