How to use the inferno-shared.warning 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-mobx / src / observer.ts View on Github external
export function observer(arg1, arg2?) {
  if (typeof arg1 === 'string') {
    throw new Error('Store names should be provided as array');
  }
  if (Array.isArray(arg1)) {
    // component needs stores
    if (!warnedAboutObserverInjectDeprecation) {
      warnedAboutObserverInjectDeprecation = true;
      warning(
        'Mobx observer: Using observer to inject stores is deprecated since 4.0. Use `@inject("store1", "store2") @observer ComponentClass` or `inject("store1", "store2")(observer(componentClass))` instead of `@observer(["store1", "store2"]) ComponentClass`'
      );
    }
    if (!arg2) {
      // invoked as decorator
      return componentClass => observer(arg1, componentClass);
    } else {
      return (inject as any).apply(null, arg1)(observer(arg2));
    }
  }
  const component = arg1;

  if (component.isMobxInjector === true) {
    warning("Mobx observer: You are trying to use 'observer' on a component that already has 'inject'. Please apply 'observer' before applying 'inject'");
  }
github infernojs / inferno / packages / inferno-mobx / src / observer.ts View on Github external
shouldComponentUpdate(nextProps, nextState) {
    if (isUsingStaticRendering) {
      warning(
        '[mobx-react] It seems that a re-rendering of a React component is triggered while in static (server-side) mode. Please make sure components are rendered only once server-side.'
      );
    }
    // update on any state changes (as is the default)
    if (this.state !== nextState) {
      return true;
    }
    // update if props are shallowly not equal, inspired by PureRenderMixin
    // we could return just 'false' here, and avoid the `skipRender` checks etc
    // however, it is nicer if lifecycle events are triggered like usually,
    // so we return true here if props are shallowly modified.
    return isObjectShallowModified(this.props, nextProps);
  }
};
github infernojs / inferno / packages / inferno-mobx / src / observer.ts View on Github external
warnedAboutObserverInjectDeprecation = true;
      warning(
        'Mobx observer: Using observer to inject stores is deprecated since 4.0. Use `@inject("store1", "store2") @observer ComponentClass` or `inject("store1", "store2")(observer(componentClass))` instead of `@observer(["store1", "store2"]) ComponentClass`'
      );
    }
    if (!arg2) {
      // invoked as decorator
      return componentClass => observer(arg1, componentClass);
    } else {
      return (inject as any).apply(null, arg1)(observer(arg2));
    }
  }
  const component = arg1;

  if (component.isMobxInjector === true) {
    warning("Mobx observer: You are trying to use 'observer' on a component that already has 'inject'. Please apply 'observer' before applying 'inject'");
  }

  // Stateless function component:
  // If it is function but doesn't seem to be a react class constructor,
  // wrap it to a react class automatically
  if (typeof component === 'function' && (!component.prototype || !component.prototype.render)) {
    return observer(
      class extends Component {
        public static displayName = component.displayName || component.name;
        public static defaultProps = component.defaultProps;
        public render(props, _state, context) {
          return component(props, context);
        }
      }
    );
  }
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) {
github infernojs / inferno / packages / inferno-hydrate / src / index.ts View on Github external
function hydrateElement(vNode: VNode, parentDOM: Element, dom: Element, context: Object, isSVG: boolean, lifecycle: Function[]) {
  const props = vNode.props;
  const className = vNode.className;
  const flags = vNode.flags;
  const ref = vNode.ref;

  isSVG = isSVG || (flags & VNodeFlags.SvgElement) > 0;
  if (dom.nodeType !== 1 || dom.tagName.toLowerCase() !== vNode.type) {
    if (process.env.NODE_ENV !== 'production') {
      warning("Inferno hydration: Server-side markup doesn't match client-side markup");
    }
    _ME(vNode, null, context, isSVG, null, lifecycle);
    parentDOM.replaceChild(vNode.dom as Element, dom);
  } else {
    vNode.dom = dom;

    hydrateChildren(vNode, dom, dom.firstChild, context, isSVG, lifecycle);

    if (!isNull(props)) {
      _MP(vNode, flags, props, dom, isSVG);
    }
    if (isNullOrUndef(className)) {
      if (dom.className !== '') {
        dom.removeAttribute('class');
      }
    } else if (isSVG) {
github infernojs / inferno / packages / inferno-mobx / src / observer.ts View on Github external
export function trackComponents() {
  if (!isDevtoolsEnabled) {
    isDevtoolsEnabled = true;
    warning('Do not turn trackComponents on in production, its expensive. For tracking dom nodes you need inferno-compat.');
  } else {
    isDevtoolsEnabled = false;
    renderReporter.listeners.length = 0;
  }
}
github infernojs / inferno / packages / inferno-compat / src / index.ts View on Github external
function normalizeFormProps<p>(name: string, props: Props</p><p> | any) {
  if ((name === 'input' || name === 'textarea') &amp;&amp; props.type !== 'radio' &amp;&amp; props.onChange) {
    const type = props.type &amp;&amp; props.type.toLowerCase();
    let eventName;

    if (!type || validLineInputs[type]) {
      eventName = 'oninput';
    }

    if (eventName &amp;&amp; !props[eventName]) {
      if (process.env.NODE_ENV !== 'production') {
        const existingMethod = props.oninput || props.onInput;

        if (existingMethod) {
          warning(
            `Inferno-compat Warning! 'onInput' handler is reserved to support React like 'onChange' event flow.
Original event handler 'function ${existingMethod.name}' will not be called.`
          );
        }
      }
      props[eventName] = props.onChange;
      props.onChange = void 0;
    }
  }
}
</p>