Skip to content

Instantly share code, notes, and snippets.

@pelonpelon
Created May 15, 2015 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pelonpelon/46e7f61fc6ad78844710 to your computer and use it in GitHub Desktop.
Save pelonpelon/46e7f61fc6ad78844710 to your computer and use it in GitHub Desktop.
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"}
}
}
}
function local(id, callback) {
return function(e) {
target = id
callback.call(this, e)
}
}
//a module
var MyModule = {
controller: function() {
this.doStuff = function() {alert(1)}
},
view: function() {
return m("button[type=button]", {
onclick: local("MyModule", ctrl.doStuff)
}, "redraw only MyModule")
}
}
//init
m.module(element, tenant("MyModule", MyModule))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment