Reputation: 1538
When using m.module
, I often would like to provide arguments to the controller constructor so that the first rendering starts with the right data. However, the Mithril documentation and examples always show module.controller()
and module.vm.init()
without parameters.
To go around this issue and have module.controller(initData)
I've resorted to use this small utility function to wrap and extend the existing m.Module:
var mModule = function (dom, mod, arg) {
return m.module(dom, {
view: mod.view,
controller: mod.controller.bind(mod.controller,arg)
});
};
Questions:
m.module
a deliberate design choice?Oh...and thanks to all involved for the existing documentation and discussions.
Upvotes: 1
Views: 641
Reputation: 1320
No, it's not an anti-pattern, and it's an idea that is explored in one of the blog articles, and also by Moria (a router extension library for Mithril)
Upvotes: 1