0

I'm trying to asynchronously load a JS file on demand (on user input), that contains another mithril module, with the asynchronous module loader technique described at http://lhorie.github.io/mithril-blog/integrating-mithril-and-requirejs.html

The only way I could make this work was to call the async load module function and instantiate the new loaded module's constructor from a base module controller that gets called from a view's onlick function. Since the documentation states that we shouldn't instantiate a new controller from a view (or call a function that does - this is my case), I was wondering if this is considered anti-pattern and if there's a better way of doing this.
Thanks in advance.

Oliver Nybroe
  • 1,828
  • 22
  • 30
humand
  • 53
  • 4

1 Answers1

0

What you're doing is fine, since the controller instance is attached to the instance of the Example's controller, and this only happens in response to a click event.

What is considered an anti-pattern is to call new something.controller inline in the view, because then the controller would be re-initialized any time a redraw happens (which is most likely not what you want)

LeoHorie
  • 1,320
  • 11
  • 11