Skip to content

Instantly share code, notes, and snippets.

@pelonpelon
pelonpelon / dropdown_select.js
Created May 15, 2015 00:21
Mithril: Dropdowns (select boxes)
var DropDownExample = {
controller: function () {
var ctrl = this
ctrl.data = m.prop([{ name: 'alice', id: 1}, { name: 'bob', id: 2 }])
ctrl.selectedId = m.prop()
},
view: function (ctrl) {
return m('select', { onchange: m.withAttr('value', ctrl.selectedId) }, [
ctrl.data().map(function(person) {
return m('option', { value: person.id }, person.name)
@pelonpelon
pelonpelon / multi_tenancy.js
Created May 15, 2015 00:30
Mithril: Multi-tenancy
//helpers
var target
function tenant(id, module) {
return {
controller: module.controller,
view: function(ctrl) {
return target == id ? module.view(ctrl) : {subtree: "retain"}
}
}
}
@pelonpelon
pelonpelon / index.html
Created June 12, 2015 23:17
Mithril experiment mithriljs: Mithril template // source http://jsbin.com/mawuzi
<!DOCTYPE html>
<html>
<head>
<title>Mithril experiment</title>
<meta name="description" content="mithriljs: Mithril template">
<meta charset="utf-8">
<script>
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
<!DOCTYPE html>
<html>
<head>
<title>Mithril experiment</title>
<meta name="description" content="mithriljs: Mithril template from Github">
<meta charset="utf-8">
<script>
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
<!DOCTYPE html>
<html>
<head>
<title>Mithril experiment</title>
<meta name="description" content="mithriljs: Mithril template">
<meta charset="utf-8">
<script>
window.log = function(){
log.history = log.history || []; // store logs to an array for reference