quick intro
do's
don'ts
components
JS-Dev since 2011
Founder of tutory.de
JS-Only Freelancer since 2014
like react
it seems uglier than it actually is
gulp, moment, backbone(-models), browserify, emberjs
it mostly works as you would expect
they are awesome
use controllers
m.mount(yourBasicDOMel, {
controller: function() {
return {
name: 'Superman'
};
},
view: function(scope) {
return m('.name', scope.name);
}
});
nameComponent = {
controller: function() {
return {
name: 'Superman'
};
},
view: function(scope) {
return m('.name', scope.name);
}
};
m.mount(yourBasicDOMel, {
controller: function() {
// ...
},
view: function(scope) {
return m('.container', nameComponent);
}
});
nameComponent = {
controller: function() {
return {
name: 'Batman'
};
},
view: function(scope) {
return m('.name', scope.name);
}
};
m.mount(yourBasicDOMel, {
controller: function() {
return {
foo: 'bar'
};
},
view: function(scope) {
return m('.baz',
m.component(barComponent, 'Superman')
);
}
});
nameComponent = {
controller: function(initialName) {
return {
name: initialName || 'Batman'
};
},
view: function(scope) {
return m('.name', scope.name);
}
};
with the help of mithril-node-render
so only pre-render indexed pages
since mithril rerenders everything on startup
var out = mithrilQuery(nameComponent, 'Catwoman');
out.should.have('.name');
out.should.not.have('.address');
out.should.have(1, '.name');
out.should.contain('Catwomen');
nameComponent = {
controller: function(initialName) {
return {
name: initialName || 'Batman'
};
},
view: function(scope) {
return m('.name', scope.name);
}
};
var out = mithrilQuery(nameComponent, 'Catwoman');
out.should.contain('Catwomen');
out.click('.clear');
out.should.not.contain('Catwomen');
nameComponent = {
controller: function(initialName) {
var scope = {
name: initialName || 'Batman'
clearName: function() {
scope.name = '';
}
};
return scope;
},
view: function(scope) {
return m('.name', scope.name);
return m('.clear', {
onclick: scope.clearName
}, 'clear');
}
};
since mithril has only one redraws cycle for all mounts
function drawCanvas(element, isInitialized) {
//don't redraw if we did once already
if (isInitialized) return;
var ctx = element.getContext("2d");
/* draws stuff */
}
var app = {
controller: function() {
// ...
},
view: {
return m("canvas", {
config: drawCanvas
})
}
]
m.mount(document.body, app);
maybe even more now
All other stuff seems so odd compared to mithril