How to use the incremental-dom.text function in incremental-dom

To help you get started, we’ve selected a few incremental-dom 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 spectjs / spect / src / html.js View on Github external
function render(arg) {
  if (arg == null) return

  // numbers/strings are serialized as text
  if (typeof arg === 'number') return text(arg)
  if (typeof arg === 'string') return text(arg)

  if (isIterable(arg)) {
    for (let el of arg) render.call(this, el)
    return
  }

  if (typeof arg === 'object' && !arg._ref && !arg._vnode) {
    return text(arg.toString())
  }

  // stub refs to native els
  if (arg._ref) return elementVoid('span', null, ['id', SPECT_CLASS + '-ref-' + arg._ref])

  // objects create elements
  let { tag, key, props, staticProps, children, use, create, fn } = arg

  // fragment (direct vdom)
  if (!tag) {
    return children && children.forEach(render, this)
  }

  let el
  if (!children || !children.length) {
    el = elementVoid(create, key, staticProps, ...props)
github spectjs / spect / src / html.js View on Github external
function render(arg) {
  if (arg == null) return

  // numbers/strings are serialized as text
  if (typeof arg === 'number') return text(arg)
  if (typeof arg === 'string') return text(arg)

  if (isIterable(arg)) {
    for (let el of arg) render.call(this, el)
    return
  }

  if (typeof arg === 'object' && !arg._ref && !arg._vnode) {
    return text(arg.toString())
  }

  // stub refs to native els
  if (arg._ref) return elementVoid('span', null, ['id', SPECT_CLASS + '-ref-' + arg._ref])

  // objects create elements
  let { tag, key, props, staticProps, children, use, create, fn } = arg
github spectjs / spect / src / min.js View on Github external
function render(arg) {
      if (!arg) return

      // numbers/strings serialized as text
      if (typeof arg === 'number') return text(arg)
      if (typeof arg === 'string') return text(arg)

      // FIXME: .length can be wrong check
      if (arg.length) return [...arg].forEach(arg => render(arg))

      // objects create elements
      let { tag, key, props, staticProps, children, use, is, effects = [] } = arg

      // fragment (direct vdom)
      if (!tag) return children.forEach(render)

      let el

      // <ul is="">
      if (is) {
        function create() { return document.createElement(tag, { is }) }
        el = elementOpen(create, key, staticProps, ...props)</ul>
github spectjs / spect / src / html-idom.js View on Github external
// numbers/strings are serialized as text
  if (typeof arg === 'number') return text(arg)
  if (typeof arg === 'string') return text(arg)

  if (isIterable(arg)) {
    for (let el of arg) render(el)
    return
  }

  if (isElement(arg)) {
    let el = elementVoid(function () { return arg })
    return
  }

  if (typeof arg === 'object' && !arg[_vnode]) return text(arg.toString())

  // objects create elements
  let { tag, key, props, staticProps, children } = arg

  // fragment (direct vdom)
  if (!tag) return children && children.forEach(render)

  let el
  if (!children || !children.length) {
    el = elementVoid(tag, key, staticProps, ...props)
  }
  else {
    el = elementOpen(tag, key, staticProps, ...props)
    children.forEach(render)
    elementClose(tag)
  }
github joshthecoder / idom-redux-todomvc-app / components / TodoItem.js View on Github external
function ReadView({todo, startEditingTodo}) {
  function onDoubleClick() {
    startEditingTodo(todo.id);

    // TODO: Better way of access the real DOM element of a component?
    // Here we want to focus the input field and set the curor to the end
    const input = document.querySelector('.edit');
    input.focus();
    input.setSelectionRange(input.value.length, input.value.length);
  }

  elementOpen('div', null, ['class', 'view']);
    elementVoid('input', null, ['class', 'toggle', 'type', 'checkbox']);
    elementOpen('label', null, null, 'ondblclick', onDoubleClick);
      text(todo.text);
    elementClose('label');
    elementVoid('button', null, ['class', 'destroy']);
  elementClose('div');
}
github spectjs / spect / src / html-idom.js View on Github external
function render(arg) {
  if (arg == null) return

  // numbers/strings are serialized as text
  if (typeof arg === 'number') return text(arg)
  if (typeof arg === 'string') return text(arg)

  if (isIterable(arg)) {
    for (let el of arg) render(el)
    return
  }

  if (isElement(arg)) {
    let el = elementVoid(function () { return arg })
    return
  }

  if (typeof arg === 'object' && !arg[_vnode]) return text(arg.toString())

  // objects create elements
  let { tag, key, props, staticProps, children } = arg
github eliot-akira / idom / src / index.js View on Github external
function create(node) {

  if (!node) return

  let nodeType = typeof node

  if (nodeType === 'function') return node()
  if (Array.isArray(node)) return node.forEach(create)
  if (nodeType === 'string' || nodeType === 'number') return text(node)

  let { tag, props, children } = node

  if (!tag) return
  props = props || {}
  children = children || []

  if (typeof tag === 'function') return tag(props, children)()

  // Prepare arguments
  // (See: http://google.github.io/incremental-dom/#api/elementOpen)
  let args = [tag, null, null]

  for (let key in props) {
    if (key==='key') {
      args[1] = props.key
github jridgewell / babel-plugin-transform-incremental-dom / test / fixtures / idom-methods / require-with-prefix / expected.js View on Github external
function render() {
  iDOM.elementOpen("div");
  iDOM.text("test");
  return iDOM.elementClose("div");
}
github node-organic / organic-oval / engines / incremental-dom.js View on Github external
const appendChilds = function (childs) {
  if (!childs) return
  for (var i = 0; i &lt; childs.length; i++) {
    var node = childs[i]
    if (typeof node === 'undefined' || node === null) continue
    if (typeof node === 'number' ||
      typeof node === 'boolean' ||
      typeof node === 'string' ||
      node instanceof Date ||
      node instanceof RegExp) {
      IncrementalDOM.text(node)
      continue
    }
    if (Array.isArray(node)) {
      appendChilds(node)
      continue
    }
    if (typeof node === 'function') {
      node()
    } else {
      console.warn('found unknown node', node)
    }
  }
}
github tailhook / khufu / khufu-runtime / src / dom.js View on Github external
export function item(value, key) {
    if(typeof value == 'function') {
        value(key)
    } else {
        text(value)
    }
}