Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding events for more than a single controller in ExtJs
    primarykey
    data
    text
    <p>I've assembled a modestly sized application and I am in the process of factoring code to reduce the overall number of maintained lines, as well as performance tuning. The use case that has me posting this question is that I have a button embedded in a menu that invokes (or needs to invoke) a method on a controller that displays a form. This currently is implemented using a direct reference to the specific button control, creating a panel, and putting that panel inside of my viewport.</p> <p>The question at: <a href="https://stackoverflow.com/questions/12065926/extjs-4-1-call-one-controller-from-another">ExtJS 4.1 Call One Controller From Another</a> begins to address the issue of best-practices near the end of responses, but doesn't really settle on a base-case that can be reproduced or extended to cover more complex implementations (which is the aim of my question.)</p> <p>Given the two controllers:</p> <h3>A "main menu" controller.</h3> <pre><code>// controller/Menu.js Ext.define("App.controller.Menu", { extend: "Ext.app.Controller", init: function () { this.control({ "viewport &gt; mainmenu &gt; button": function (ctl, evt) { } }); } }); </code></pre> <h3>A user account controller</h3> <pre><code>// controller/User.js Ext.define("App.controller.User", { extend: "Ext.app.Controller", stores: ["User"], views: ["user.Edit", "user.List"], init: function () { } }); </code></pre> <h3>The Question</h3> <p>What would be the (best) way to implement a crosswise connection between the two controllers to properly delegate the responsibility of responding to a click event on the menu button for "Create a New Account?"</p> <h3>One Possible Solution</h3> <p>Using componentquery I can <em>easily</em> narrow down the focus of the button in the main menu view using a tag property such that the User controller is responding directly to the event:</p> <pre><code>// controller/User.js "viewport &gt; mainmenu &gt; button [tag=user.create]": function () {} </code></pre> <h3>An unknown alternative</h3> <p>Or I could possible winnow my way through the object graph to find the reference to the User controller from the Menu controller and invoke it that way.</p> <pre><code>// controller/Menu.js // switch on tag case "user.create" App.controller.User.createUserForm() </code></pre> <h3>The real question</h3> <p>The question that results from all of this is what the "most acceptable" solution is here. One could imagine the use of a third, mediating controller, to "route" requests from controls to controllers but I think that goes against what the remainder of the framework is attempting to do. Using a variation of either of these methods currently works however neither feels completely clean and reliable; or ultimately maintainable long-term (as code gets spread out rather quickly.) Additionally the thought had occurred to us to drop into raw events but we run into the same kind of maintainability issues there.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload