Created
May 15, 2015 00:30
-
-
Save pelonpelon/46e7f61fc6ad78844710 to your computer and use it in GitHub Desktop.
Mithril: Multi-tenancy
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
//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