I have a couple lines of duplicate code
Ember.$(".close").trigger('click'); window.parent.showRegister();
in: adapters
, controllers
and routes
.
Where the best place to write helper (function or action) and executing this in different places.
For example I can write function in controller
, but I don't know how access controllers
in RESTAdapter
.
The main reason why you can or can't access to some abstractions from another is control of software complexity, an attempt to keep it to a minimum. There are principles like SOLID, low coupling / high cohesion to follow which helps us to maintain complex software systems, to increase comprehensibility of a system and to decrease possibility of an error in development process.
Ember is follow the MVC pattern in some way, and because of that I wouldn't advise (1) to keep code for DOM manipulation in controller/adapter/router and (2) to couple adapters, controllers and routes in such a way. I'am sure there is a way to put this code in View or in module outside of Ember.App classes; or to set up routing map handling this case.
If it's not the case or you need a simple and straight solution, you can use ugly-magic constructions to access anything from everywhere in Ember:
App.__container__.lookup('controller:controllerName'); // controllers
App.__container__.lookup('router:main'); // routes
App.__container__.lookup('store:main'); // store, adapters, serializers
Ember.View.views['emberViewId'] // objects are dying here occasionally
Double underscore tells us that this is not the recommended way to build communications in application. :)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments