Skip to content

Commit

Permalink
added a small validation around providing a name for a custom element
Browse files Browse the repository at this point in the history
  • Loading branch information
avigoldman committed Oct 22, 2017
1 parent fc57b2d commit 2745a32
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/heml-utils/src/createElement.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { defaults, isFunction } from 'lodash'

export default function (name, element) {
if (!name || name.trim().length === 0) {
throw new Error(`When creating an element, you must set the name. ${name.trim().length === 0 ? 'An empty string' : `"${name}"`} was given.`)
}

if (isFunction(element)) {
element = { render: element }
}

element = defaults({}, element, {
tagName: name,
element = defaults({}, element || {}, {
tagName: name.trim().toLowerCase(),
attrs: [],
children: true,
defaultAttrs: {},
Expand Down

0 comments on commit 2745a32

Please sign in to comment.