Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"license": "MIT",
"repository": "git@github.com:auth0/charata.git",
"dependencies": {
"incremental-dom": "^0.1.0"
"incremental-dom": "^0.3.0"
},
"devDependencies": {
"babel": "^5.8.20",
Expand Down
29 changes: 18 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import ID from 'incremental-dom';

// TODO: Complete
const TAGS = [
'div', 'span', 'ul', 'li',
'form', 'button', 'i',
'a', 'h1', 'h2', 'h3',
'h4', 'h5', 'table', 'td', 'tr',
'tbody', 'thead'
'tbody', 'thead', 'label', 'fieldset'
];

const SELF_CLOSING_TAGS = [
Expand All @@ -24,8 +23,9 @@ export class EL {
* @param {string} tag the specific HTML TAG of the Element.
* @param {null|String|EL|Array} content
* @param {Array} props
* @param {Array} dynamic props
*/
constructor(tag, content=null, key='', props=[]) {
constructor(tag, content=null, key='', props=[], dynProps=[]) {
this.tag = tag;

this.content = content;
Expand All @@ -41,20 +41,27 @@ export class EL {

this.key = key;
this.props = props;
this.dynProps = dynProps;
}

/**
* renders this element and its children.
*/
render() {
if (null === this.content) {
ID.elementVoid(this.tag, this.key, this.props);
ID.elementVoid(this.tag, this.key, this.props, ...this.dynProps);
return;
}

ID.elementOpen(this.tag, this.key, this.props);
ID.elementOpen(this.tag, this.key, this.props, ...this.dynProps);

this.content.forEach((c) => c.render());
this.content.forEach((c) => {
if(typeof c === 'string'){
ID.text(c);
return;
}
c.render();
});

ID.elementClose(this.tag);
}
Expand All @@ -81,16 +88,16 @@ class TEXT {
}

let pub = TAGS.reduce((prev, tag) => {
prev[tag] = (elms, key, props) => {
return new EL(tag, elms, key, props);
prev[tag] = (elms, key, props, dynProps) => {
return new EL(tag, elms, key, props, dynProps);
}

return prev;
}, {});

SELF_CLOSING_TAGS.reduce((prev, tag) => {
prev[tag] = (key, props) => {
return new EL(tag, null, key, props);
prev[tag] = (key, props, dynProps) => {
return new EL(tag, null, key, props, dynProps);
}

return prev;
Expand All @@ -99,4 +106,4 @@ SELF_CLOSING_TAGS.reduce((prev, tag) => {
// Generic Element builder
pub.el = (tag, elms, key, props) => new EL(tag, elms, key, props);

export default pub;
export default pub;