ember.js - Accepted practice to reset a bunch of controllers -
In many cases, in my app I need to reset a set of controllers (Ajax in reply, ...) . It occurs on different points in the application, so I always have a route / controller / view not available.
I am trying to change all this (the old version of Amber):
Reset the function () {Dashboard. Ritter TotalsController.set ("content", 0); Dashboard Ritter Total minutes controller.Set ("content", 0); Dashboard Kravdar QLD NNAGC Controller.Set ("Content", 0); }; And now I am doing:
function reset () {var container = dashboard .__ container__; Container. Lookup ('Controller: Total Call'). Set ("content", 0); Container. Lookup ('Controller: Total minutes'). Set ("content", 0); Container.Locoup ('Controller: CollusionAgument'). Set ("content", 0); } But according to the container it should not be used for that. If I only have access to the application object, how do I get one controller? Before it was easy: In Dasboard.router we can reach all the controllers directly. Now only through container , but this advice has not been given, and possibly has to be changed (API N Flux). So what can I do?
If you are going the most fearlessly, but to stay outside of the function Amber, Patterns suggest you at any time created a controller in an abstract, you subscribe to it at the global reset function. There are some ways to accomplish this, maybe I want to do it with a mixin.
Here's a small example:
App.ResettableMixin = Em.Mixin.create ({Init: function () {this._super (); app reset Eligible. Joint (this .set ('reseterm'), this);}}); App.IndexController = Em.ArrayController.extend (App.ResettableMixin, {resetMe: function () {console.log ('Reset Index Controller');}}); App.FooController = Em.ObjectController.extend (App.ResettableMixin, {resetMe: function () {console.log ('Reset Foo Controller' + this.get ('model'));}}); App.Resettable = {resetters: [], join: function (method, tools, context) {this.resetters.push ({method: methodToCall, context: context}); }, Reset: function () {var item; Console.log ('reset' + this.resetters.length + 'item'); (Var i = 0, len = this.resetters.length; i & lt; len; i ++) {items = this.resetters [i]; Item.method.apply (item.context); }}, Remove: function (methodToFind) {// iterative through repeat}};
Comments
Post a Comment