Created
July 7, 2015 15:25
-
-
Save Satyam/9c3ec9014855f69e5fd0 to your computer and use it in GitHub Desktop.
Mithirl example (http://lhorie.github.io/mithril/getting-started.html#summary) converted to ES6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Mithirl ES6 test</title> | |
<meta charset="UTF-8"> | |
<script src="http://cdn.jsdelivr.net/mithril/0.2.0/mithril.min.js"></script> | |
<script src="node_modules/babel-core/browser.js"></script> | |
</head> | |
<body> | |
<script type="text/ecmascript-6"> | |
class TodoItem { | |
constructor(data) { | |
this.descr = m.prop(data.descr); | |
this.done = m.prop(false); | |
} | |
} | |
class Todo { | |
constructor() { | |
this.list = []; | |
this.descr = m.prop(""); | |
} | |
add() { | |
if (this.descr()) { | |
this.list.push(new TodoItem({ | |
descr: this.descr() | |
})); | |
this.descr(""); | |
} | |
} | |
static view(todo) { | |
return [ | |
m("input", { | |
onchange: m.withAttr("value", todo.descr), | |
value: todo.descr() | |
}), | |
m("button", { | |
onclick: todo.add.bind(todo) | |
}, "Add"), | |
m("table", todo.list.map(task => m("tr", [ | |
m("td", | |
m("input[type=checkbox]", { | |
onclick: m.withAttr("checked", task.done), | |
checked: task.done() | |
}) | |
), | |
m("td", { | |
style: { | |
textDecoration: task.done() ? "line-through" : "none" | |
} | |
}, task.descr()), | |
]) | |
) | |
) | |
]; | |
} | |
} | |
m.mount(document, { | |
controller: Todo, | |
view: Todo.view | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment