How to use the inferno-shared.isInvalid 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-server / src / renderToString.ts View on Github external
const renderOutput = instance.render(props, instance.state, instance.context);
      // In case render returns invalid stuff
      if (isInvalid(renderOutput)) {
        return '';
      }
      if (isString(renderOutput)) {
        return escapeText(renderOutput);
      }
      if (isNumber(renderOutput)) {
        return renderOutput + '';
      }
      return renderVNodeToString(renderOutput, vNode, childContext);
    } else {
      const renderOutput = type(props, context);

      if (isInvalid(renderOutput)) {
        return '';
      }
      if (isString(renderOutput)) {
        return escapeText(renderOutput);
      }
      if (isNumber(renderOutput)) {
        return renderOutput + '';
      }
      return renderVNodeToString(renderOutput, vNode, context);
    }
  } else if ((flags & VNodeFlags.Element) !== 0) {
    let renderedString = `<${type}`;
    let html;

    const isVoidElement = voidElements.has(type);
    const className = vNode.className;
github infernojs / inferno / packages / inferno-server / src / renderToString.ts View on Github external
instance.state = pending;
          } else {
            for (const key in pending) {
              state[key] = pending[key];
            }
          }
          instance.$PSS = false;
          instance.$PS = null;
        }
      }
      if (hasNewAPI) {
        instance.state = createDerivedState(instance, props, instance.state);
      }
      const renderOutput = instance.render(props, instance.state, instance.context);
      // In case render returns invalid stuff
      if (isInvalid(renderOutput)) {
        return '';
      }
      if (isString(renderOutput)) {
        return escapeText(renderOutput);
      }
      if (isNumber(renderOutput)) {
        return renderOutput + '';
      }
      return renderVNodeToString(renderOutput, vNode, childContext);
    } else {
      const renderOutput = type(props, context);

      if (isInvalid(renderOutput)) {
        return '';
      }
      if (isString(renderOutput)) {
github infernojs / inferno / packages / inferno-server / src / renderToString.queuestream.ts View on Github external
}
        const renderOutput = instance.render(instance.props, instance.state, instance.context);

        if (isInvalid(renderOutput)) {
          this.addToQueue('', position);
        } else if (isString(renderOutput)) {
          this.addToQueue(escapeText(renderOutput), position);
        } else if (isNumber(renderOutput)) {
          this.addToQueue(renderOutput + '', position);
        } else {
          this.renderVNodeToQueue(renderOutput, context, position);
        }
      } else {
        const renderOutput = type(props, context);

        if (isInvalid(renderOutput)) {
          this.addToQueue('', position);
        } else if (isString(renderOutput)) {
          this.addToQueue(escapeText(renderOutput), position);
        } else if (isNumber(renderOutput)) {
          this.addToQueue(renderOutput + '', position);
        } else {
          this.renderVNodeToQueue(renderOutput, context, position);
        }
      }
      // If an element
    } else if ((flags & VNodeFlags.Element) > 0) {
      let renderedString = `<${type}`;
      let html;
      const isVoidElement = voidElements.has(type);
      const className = vNode.className;
github infernojs / inferno / packages / inferno-hydrate / src / index.ts View on Github external
export function hydrate(input, parentDOM: Element, callback?: Function) {
  let dom = parentDOM.firstChild as Element;

  if (isNull(dom)) {
    if (process.env.NODE_ENV !== 'production') {
      warning("Inferno hydration: Server-side markup doesn't match client-side markup");
    }
    render(input, parentDOM, callback);
  } else {
    const lifecycle: Function[] = [];

    if (!isInvalid(input)) {
      dom = hydrateVNode(input, parentDOM, dom, {}, false, lifecycle) as Element;
    }
    // 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;
github infernojs / inferno / packages / inferno-server / src / renderToString.queuestream.ts View on Github external
return promisePosition;
                }),
                position
              );
              return;
            } else {
              instance.props = combineFrom(instance.props, initialProps);
            }
          }
        }
        if (hasNewAPI) {
          instance.state = createDerivedState(instance, props, instance.state);
        }
        const renderOutput = instance.render(instance.props, instance.state, instance.context);

        if (isInvalid(renderOutput)) {
          this.addToQueue('', position);
        } else if (isString(renderOutput)) {
          this.addToQueue(escapeText(renderOutput), position);
        } else if (isNumber(renderOutput)) {
          this.addToQueue(renderOutput + '', position);
        } else {
          this.renderVNodeToQueue(renderOutput, context, position);
        }
      } else {
        const renderOutput = type(props, context);

        if (isInvalid(renderOutput)) {
          this.addToQueue('', position);
        } else if (isString(renderOutput)) {
          this.addToQueue(escapeText(renderOutput), position);
        } else if (isNumber(renderOutput)) {
github infernojs / inferno / packages / inferno-server / src / renderToString.stream.ts View on Github external
public renderComponent(vComponent, context, isClass) {
    const type = vComponent.type;
    const props = vComponent.props;

    if (!isClass) {
      const renderOutput = type(props, context);

      if (isInvalid(renderOutput)) {
        return this.push('');
      }
      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;
github infernojs / inferno / packages / inferno-compat / src / index.ts View on Github external
forEach(children: Array, fn: IterateChildrenFn, ctx?: any): void {
    if (isNullOrUndef(children)) {
      return;
    }
    children = Children.toArray(children);
    if (ctx) {
      fn = fn.bind(ctx);
    }
    for (let i = 0, len = children.length; i < len; ++i) {
      const child = isInvalid(children[i]) ? null : children[i];

      fn(child, i, children);
    }
  },
  count(children: Array): number {
github infernojs / inferno / packages / inferno-router / src / Switch.ts View on Github external
public render(): VNode | null {
    const { route } = this.context.router;
    const { children } = this.props;
    const location = this.props.location || route.location;

    if (isInvalid(children)) {
      return null;
    }

    const { match, _child } = extractMatchFromChildren(children, route, location);

    if (match) {
      return createComponentVNode(_child.flags, _child.type, combineFrom(_child.props, { location, computedMatch: match }));
    }

    return null;
  }
}
github infernojs / inferno / packages / inferno-server / src / renderToString.queuestream.ts View on Github external
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)) {
                    this.addToQueue(renderOut + '', promisePosition);
                  } else {
                    this.renderVNodeToQueue(renderOut, instance.context, promisePosition);
                  }

                  setTimeout(this.pushQueue, 0);
                  return promisePosition;
                }),
                position
github infernojs / inferno / packages / inferno-server / src / renderToString.stream.ts View on Github external
instance.state = pending;
        } else {
          for (const key in pending) {
            state[key] = pending[key];
          }
        }
        instance.$PS = null;
      }

      instance.$BR = false;
      if (hasNewAPI) {
        instance.state = createDerivedState(instance, props, instance.state);
      }
      const renderOutput = instance.render(instance.props, instance.state, instance.context);

      if (isInvalid(renderOutput)) {
        return this.push('');
      }
      if (isString(renderOutput)) {
        return this.push(escapeText(renderOutput));
      }
      if (isNumber(renderOutput)) {
        return this.push(renderOutput + '');
      }

      return this.renderNode(renderOutput, context);
    });
  }