How to use the snabbdom/is.primitive 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') {
    addNS(data, children)
  }
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])
github motorcyclejs / motorcyclejs / dom / src / hyperscript / h.js View on Github external
} 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') {
    addNS(data, children)
  }
  return vnode(sel, data, children, text, undefined)
};
github cyclejs / cyclejs / dom / src / hyperscript.ts View on Github external
} 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);
};
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);
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') {
    addNS(data, children, sel);
  }