Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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
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>
// 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)
}
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');
}
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
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
function render() {
iDOM.elementOpen("div");
iDOM.text("test");
return iDOM.elementClose("div");
}
const appendChilds = function (childs) {
if (!childs) return
for (var i = 0; i < 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)
}
}
}
export function item(value, key) {
if(typeof value == 'function') {
value(key)
} else {
text(value)
}
}