Skip to content

Commit

Permalink
inoxjs: require the classt list of components to start with a capital…
Browse files Browse the repository at this point in the history
…ized class name
  • Loading branch information
GraphR00t committed Apr 30, 2024
1 parent 529bd65 commit d388766
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions internal/inoxjs/inox-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
function initComponent(arg) {
const componentRoot = arg.element ?? /** @type {HTMLElement} */(me())

if(! isComponentRootElement(componentRoot)){
console.error(componentRoot, 'is not a valid component root element, class list should start with a capitalized class name')
return
}

//register signals

const signals = arg.signals ?? {}
Expand Down Expand Up @@ -251,8 +256,6 @@
}
}
}

console.log(node)
})

//rendering
Expand Down Expand Up @@ -518,7 +521,14 @@
* @returns {boolean}
*/
function isComponentRootElement(node) {
return (node instanceof HTMLElement) && Array.from(node.classList).some(className => className[0].toUpperCase() == className[0])
if(!(node instanceof HTMLElement)) {
return false
}
const firstClassName = node.classList.item(0)
if(firstClassName === null){
return false
}
return (/[A-Z]/).test(firstClassName[0])
}

/**
Expand Down

0 comments on commit d388766

Please sign in to comment.