Where I can write helper in ember to avoid code duplication

user1156168

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.

Microfed

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I avoid code duplication?

From Dev

How can I avoid this code duplication?

From Dev

How can I avoid this code duplication?

From Dev

Can I use decltype() to avoid code duplication in explicit template instantiations?

From Dev

Kotlin: How can I avoid code duplication in constructors?

From Dev

How Can I Refactor To Avoid Duplication?

From Dev

Java: How to avoid code duplication between display() and write(pdf)

From Dev

how to write a true default method to avoid code duplication

From Dev

Avoid code duplication

From Dev

CRTP to avoid code duplication : can't assignment Base=Derived by value

From Dev

How do I avoid duplication of code using AASM?

From Dev

How can I reduce code duplication in this JavaScript?

From Dev

How can i solve duplication of code in this?

From Dev

How can I reduce code duplication in this JavaScript?

From Java

How can I avoid DTOs duplication without inheritance?

From Dev

How can i avoid duplication while joining two tables

From Dev

How can I avoid DTOs duplication without inheritance?

From Dev

Avoid code duplication by using inheritance

From Dev

Avoid code duplication in Rspec + Capybara

From Dev

Avoid code duplication over classes

From Dev

OOP ajax to avoid code duplication

From Dev

Avoid code duplication by using inheritance

From Dev

avoid code duplication in C++

From Dev

How can I make an input where I can write javascript code which then can be saved in a script?

From Dev

How to avoid code duplication in Code Contracts statements

From Dev

How to avoid statement duplication in where clause in MySQL?

From Dev

Use lambda or helper method in python to avoid for loop duplication

From Dev

How can I add Levels to my game with less duplication of code?

From Dev

How can I avoid ember-simple-auth OPTIONS call?

Related Related

  1. 1

    How can I avoid code duplication?

  2. 2

    How can I avoid this code duplication?

  3. 3

    How can I avoid this code duplication?

  4. 4

    Can I use decltype() to avoid code duplication in explicit template instantiations?

  5. 5

    Kotlin: How can I avoid code duplication in constructors?

  6. 6

    How Can I Refactor To Avoid Duplication?

  7. 7

    Java: How to avoid code duplication between display() and write(pdf)

  8. 8

    how to write a true default method to avoid code duplication

  9. 9

    Avoid code duplication

  10. 10

    CRTP to avoid code duplication : can't assignment Base=Derived by value

  11. 11

    How do I avoid duplication of code using AASM?

  12. 12

    How can I reduce code duplication in this JavaScript?

  13. 13

    How can i solve duplication of code in this?

  14. 14

    How can I reduce code duplication in this JavaScript?

  15. 15

    How can I avoid DTOs duplication without inheritance?

  16. 16

    How can i avoid duplication while joining two tables

  17. 17

    How can I avoid DTOs duplication without inheritance?

  18. 18

    Avoid code duplication by using inheritance

  19. 19

    Avoid code duplication in Rspec + Capybara

  20. 20

    Avoid code duplication over classes

  21. 21

    OOP ajax to avoid code duplication

  22. 22

    Avoid code duplication by using inheritance

  23. 23

    avoid code duplication in C++

  24. 24

    How can I make an input where I can write javascript code which then can be saved in a script?

  25. 25

    How to avoid code duplication in Code Contracts statements

  26. 26

    How to avoid statement duplication in where clause in MySQL?

  27. 27

    Use lambda or helper method in python to avoid for loop duplication

  28. 28

    How can I add Levels to my game with less duplication of code?

  29. 29

    How can I avoid ember-simple-auth OPTIONS call?

HotTag

Archive