Skip to content

Instantly share code, notes, and snippets.

@tinchoz49
Created March 18, 2015 17:03
Show Gist options
  • Save tinchoz49/3656c6a8c62b05a6e4bb to your computer and use it in GitHub Desktop.
Save tinchoz49/3656c6a8c62b05a6e4bb to your computer and use it in GitHub Desktop.
components in mithril
var app = {},
buttonComponent = {};
buttonComponent.controller = function ( options ) {
this.title = options.title;
};
buttonComponent.view = function ( ctrl ) {
return m('button', 'The button component: ' + ctrl.title());
};
app.controller = function () {
this.title = m.prop('idea');
};
app.view = function ( ctrl ) {
return [
m('h1', ctrl.title()),
m(buttonComponent, { title: ctrl.title })
];
};
m.mount(document.getElementById('app'), app); // or maybe m.render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment