@azothjs/maya
Advanced tools
Comparing version 0.4.1 to 0.4.3
@@ -70,3 +70,2 @@ import { Controller } from '../renderer/renderer.js'; | ||
swapById(a, b) { | ||
const { container } = this; | ||
const aNode = this.getById(a); | ||
@@ -76,4 +75,4 @@ const bNode = this.getById(b); | ||
aNode.replaceWith(bNode); | ||
beforeB ? beforeB.after(aNode) : container.prepend(aNode); | ||
beforeB ? beforeB.after(aNode) : this.container.prepend(aNode); | ||
} | ||
} |
@@ -85,3 +85,8 @@ export const IGNORE = Symbol.for('azoth.compose.IGNORE'); | ||
const isRenderObject = obj => obj && typeof obj === 'object' && obj.render && typeof obj.render === 'function'; | ||
/** | ||
* Duck type test for render object | ||
* @param {object} obj | ||
* @returns {boolean} | ||
*/ | ||
const isRenderObject = obj => typeof obj?.render === 'function'; | ||
@@ -98,7 +103,10 @@ export function composeComponent(anchor, [Constructor, props, slottable]) { | ||
export function createComponent(Constructor, props, slottable) { | ||
const result = create(Constructor, props, slottable, null); | ||
let result = create(Constructor, props, slottable, null); | ||
switch(typeof result) { | ||
case 'number': | ||
case 'bigint': | ||
result = `${result}`; | ||
// eslint-disable-next-line no-fallthrough | ||
case 'string': | ||
case 'number': | ||
return document.createTextNode(result); | ||
@@ -195,4 +203,4 @@ default: | ||
// TODO: how to guard for azoth comments only? | ||
if(previousSibling.nodeType === Node.COMMENT_NODE) { | ||
// TODO: how to guard for azoth comments only? | ||
clear(previousSibling); | ||
@@ -211,3 +219,4 @@ } | ||
if(!keepLast) clear(anchor); | ||
// TODO: optimize arrays here if Node[] | ||
// TODO: optimize arrays here if Node[] research shows gain. | ||
// vanillajs-1 in jsperf benchmarks has specific numbers | ||
for(let i = 0; i < array.length; i++) { | ||
@@ -227,3 +236,5 @@ compose(anchor, array[i], true); | ||
async function composeAsyncIterator(anchor, iterator, keepLast, props, slottable) { | ||
// TODO: use iterator and intercept system messages | ||
// TODO: use iterator directly and | ||
// - control return when removed, and maybe throws on error | ||
// - possible yield/return semantics for third communication channel | ||
for await(const value of iterator) { | ||
@@ -230,0 +241,0 @@ compose(anchor, value, keepLast, props, slottable); |
{ | ||
"name": "@azothjs/maya", | ||
"version": "0.4.1", | ||
"version": "0.4.3", | ||
"description": "Azoth runtime", | ||
@@ -5,0 +5,0 @@ "author": "Marty Nelson", |
@@ -23,2 +23,3 @@ const QUERY_SELECTOR = '[data-bind]'; | ||
}, | ||
getById(id) { | ||
@@ -42,2 +43,3 @@ const template = document.getElementById(id); | ||
}, | ||
bound(dom) { | ||
@@ -44,0 +46,0 @@ return dom.querySelectorAll(QUERY_SELECTOR); |
18229
492