MCPcopy
hub / github.com/anthonyshort/deku / toNativeElement

Function toNativeElement

lib/render.js:427–456  ·  view source on GitHub ↗

* Create a native element from a virtual element.

(entityId, path, vnode)

Source from the content-addressed store, hash-verified

425 */
426
427 function toNativeElement (entityId, path, vnode) {
428 var el
429 var attributes = vnode.attributes
430 var tagName = vnode.type
431 var childNodes = vnode.children
432
433 // create element either from pool or fresh.
434 if (svg.isElement(tagName)) {
435 el = document.createElementNS(svg.namespace, tagName)
436 } else {
437 el = document.createElement(tagName)
438 }
439
440 // set attributes.
441 forEach(attributes, function (value, name) {
442 setAttribute(entityId, path, el, name, value)
443 })
444
445 // add children.
446 forEach(childNodes, function (child, i) {
447 var childEl = toNative(entityId, path + '.' + i, child)
448 if (!childEl.parentNode) el.appendChild(childEl)
449 })
450
451 // store keys on the native element for fast event handling.
452 el.__entity__ = entityId
453 el.__path__ = path
454
455 return el
456 }
457
458 /**
459 * Create a native element from a virtual element.

Callers 1

toNativeFunction · 0.85

Calls 2

setAttributeFunction · 0.85
toNativeFunction · 0.85

Tested by

no test coverage detected