This document provides guidance on communicating between different layers in Ember, such as between routes, controllers, views, and templates. It lists several standard Ember approaches for accessing models, routes, controllers, and views from different layers. These include using this.modelFor(), this.get('target'), needs: [], and this.get('controller'). It also presents some non-ideal but possible approaches as emergency options, like manually connecting layers through init functions or using the container lookup. The document aims to help understand how information flows between layers in Ember.
1 of 15
Downloaded 13 times
More Related Content
How to Call A from B in Ember
1. How to Call A From B in Ember
Some ideas to try before you go crazy
Ben Donaldson, Crowdly
2. Ember has many layers
Like an onion
Or a sandwich
Or a skyscraper
Or your LiveJournal
4. How do I talk between layers?
Do those ways still work?
Is it the Ember Way?
5. How do I talk between layers?
Ill list a bunch of ways that I found
Do those ways still work?
Yes, at least for the last few weeks
Is it the Ember Way?
Until it stops working
7. The List
free to use!*
*You agree, to the fullest extent permitted by law, to indemnify and hold harmless Ben Donaldson against all damages, liabilities or costs, including reasonable attorneys' fees
and defense costs, to the extent caused by your negligent performance of professional services under this Agreement and that of anyone for whom you are legally liable.
You agree, to the fullest extent permitted by law, to indemnify and hold harmless Ben Donaldson against all damages, liabilities or costs, including reasonable attorneys' fees
and defense costs, to the extent caused by your negligent acts in connection with the Project and the acts of anyone for whom you are legally liable.
Neither you or I shall be obligated to indemnify the other party in any manner whatsoever for the other party's negligence.
Modifications to this Agreement.
Ben Donaldson reserves the right to change or modify any of the terms and conditions contained in this Agreement at any time. You acknowledge and agree that it is your
responsibility to review the Presentation and these Terms of Service from time to time. Your continued use of the Presentation after such modifications to this Agreement will
constitute acknowledgment of the modified Terms of Service and agreement to abide and be bound by the modified Terms of Service.
Unlike kangaroos and eucalyptus-eating possums, koalas are hindgut fermenters, and their digestive retention can last for up to 100 hours in the wild, or up to 200 hours in
captivity. This is made possible by the extraordinary length of their caecum200 cm (80 in) long and 10 cm (4 in) in diameterthe largest proportionally of any animal. Koalas
can select which food particles to retain for longer fermentation and which to pass through. Large particles typically pass through more quickly, as they would take more time
to digest. While the hindgut is proportionally larger in the koala than in other herbivores, only 10% of the animal's energy is obtained from fermentation. Since the koala gains
a low amount of energy from its diet, its metabolic rate is half that of a typical mammal, although this can vary between seasons and sexes. The koala conserves water by
passing relatively dry faecal pellets high in undigested fibre, and by storing water in the caecum.
8. The List
Well have two models, called Apple and Orange
Each has their own route, controller, view, and template
This is just for the simplest case
9. When Im AppleRoute
Apple (the model)
this.modelFor(apple)
OrangeRoute
this.get(router).getHandler(orange)
AppleController
this.controllerFor(apple)
AppleView - no idea
Apple Template - no idea
10. When Im AppleController
Apple (the model)
this.get(content) (if its an Ember.ObjectController)
AppleRoute
this.get(target) (if youre currently on that route)
OrangeController
needs: [orange] (in the root of AppleController)
this.get(controllers.orange)
AppleView - no idea
Apple Template - no idea
11. When Im AppleView
Apple (the model)
this.get(context) (if AppleController is an Ember.ObjectController)
this.get(controller.content) (if AppleController is an Ember.ObjectController)
AppleRoute
this.get(controller.target) (if youre currently on that route)
AppleController
this.get(controller)
OrangeView - no idea
Apple Template
this.get(template) (for the handlebars function, but you wouldnt touch that much)
this.get(element) (for the DOM element)
12. When Im the Apple Template
Apple (the model)
this.get(view.context) (if AppleController is an Ember.ObjectController)
this.get(controller.content) (if AppleController is an Ember.ObjectController)
AppleRoute
this.get(controller.target) (if youre currently on that route)
AppleController
this.get(controller)
AppleView
this.get(view)
Orange Template - no idea
13. In case of emergency...
Warning: these are not elegant or the Ember Way but could let you meet a deadline
Make an init function and make manual connections
AppleView = Em.View.extend({
init: function() {
this.get(controller).set(yourAppleView, this);
}
}
Ask the almighty container, available pretty much everywhere in your app.
this.get(container).lookup(view:apple)