How to use the snabbdom/is.array function in snabbdom

To help you get started, we’ve selected a few snabbdom 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 motorcyclejs / motorcyclejs / dom / src / hyperscript / h.js View on Github external
export function h (sel, b, c) { // eslint-disable-line complexity
  let data = {}
  let children
  let text
  let i
  if (arguments.length === 3) {
    data = b
    if (is.array(c)) {
      children = c
    } else if (is.primitive(c)) {
      text = c
    }
  } else if (arguments.length === 2) {
    if (is.array(b)) {
      children = b
    } else if (is.primitive(b)) {
      text = b
    } else {
      data = b
    }
  }
  if (is.array(children)) {
    children = children.filter(x => x) // handle null/undef children
    for (i = 0; i < children.length; ++i) {
      if (is.primitive(children[i])) {
        children[i] = vnode(undefined, undefined, undefined, children[i])
      }
    }
  }
  if (sel[0] === 's' && sel[1] === 'v' && sel[2] === 'g') {
github cyclejs / cyclejs / dom / src / hyperscript.ts View on Github external
function addNS(data: any,
               children: Array> | undefined,
               selector: string | undefined): void {
  data.ns = `http://www.w3.org/2000/svg`;
  if (selector !== `text` && selector !== `foreignObject` &&
        typeof children !== 'undefined' && is.array(children)) {
    for (let i = 0; i < children.length; ++i) {
      if (isGenericStream(children[i])) {
        children[i] = (children[i] as Stream).map(mutateStreamWithNS);
      } else {
        addNS(
          (children[i] as VNode).data,
          (children[i] as VNode).children,
          (children[i] as VNode).sel,
        );
      }
    }
  }
}
github cyclejs / cyclejs / dom / src / hyperscript.ts View on Github external
export function h(sel: string, b?: any, c?: any): VNode {
  let data = {};
  let children: Array | undefined;
  let text: string | undefined;
  if (arguments.length === 3) {
    data = b;
    if (is.array(c)) {
      children = c;
    } else if (is.primitive(c)) {
      text = c as string;
    }
  } else if (arguments.length === 2) {
    if (is.array(b)) {
      children = b;
    } else if (is.primitive(b)) {
      text = b as string;
    } else {
      data = b;
    }
  }
  if (is.array(children)) {
    children = children.filter(x => !!x);
    for (let i = 0; i < children.length; ++i) {
github cyclejs / cyclejs / dom / src / hyperscript.ts View on Github external
export function h(sel: string, b?: any, c?: any): VNode {
  let data = {};
  let children: Array | undefined;
  let text: string | undefined;
  if (arguments.length === 3) {
    data = b;
    if (is.array(c)) {
      children = c;
    } else if (is.primitive(c)) {
      text = c as string;
    }
  } else if (arguments.length === 2) {
    if (is.array(b)) {
      children = b;
    } else if (is.primitive(b)) {
      text = b as string;
    } else {
      data = b;
    }
  }
  if (is.array(children)) {
    children = children.filter(x => !!x);
    for (let i = 0; i < children.length; ++i) {
      if (is.primitive(children[i])) {
        children[i] = vnode(undefined as any, undefined, undefined, children[i] as any, undefined);
      }
    }
  }
  if (sel[0] === 's' && sel[1] === 'v' && sel[2] === 'g') {
github cyclejs / cyclejs / dom / src / hyperscript.ts View on Github external
data = b;
    if (is.array(c)) {
      children = c;
    } else if (is.primitive(c)) {
      text = c as string;
    }
  } else if (arguments.length === 2) {
    if (is.array(b)) {
      children = b;
    } else if (is.primitive(b)) {
      text = b as string;
    } else {
      data = b;
    }
  }
  if (is.array(children)) {
    children = children.filter(x => !!x);
    for (let i = 0; i < children.length; ++i) {
      if (is.primitive(children[i])) {
        children[i] = vnode(undefined as any, undefined, undefined, children[i] as any, undefined);
      }
    }
  }
  if (sel[0] === 's' && sel[1] === 'v' && sel[2] === 'g') {
    addNS(data, children, sel);
  }
  return vnode(sel, data, children, text, undefined);
};