15
How to Call A From B in Ember Some ideas to try before you go crazy Ben Donaldson, Crowdly

How to Call A from B in Ember

Embed Size (px)

DESCRIPTION

A quick cheat sheet for Ember communication between layers

Citation preview

Page 1: How to Call A from B in Ember

How to Call A From B in Ember

Some ideas to try before you go crazy

Ben Donaldson, Crowdly

Page 2: How to Call A from B in Ember

Ember has many layers

Like an onionOr a sandwichOr a skyscraperOr your LiveJournal

Page 3: How to Call A from B in Ember

Ember has many changes

Page 4: How to Call A from B in Ember

How do I talk between layers?

Do those ways still work?

Is it the “Ember Way”?

Page 5: How to Call A from B in Ember

How do I talk between layers?

Do those ways still work?

Is it the “Ember Way”?

I’ll list a bunch of ways that I found

Yes, at least for the last few weeks

Until it stops working

Page 6: How to Call A from B in Ember

The List

Page 7: How to Call A from B in Ember

The Listfree 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 caecum—200 cm (80 in) long and 10 cm (4 in) in diameter—the 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.

Page 8: How to Call A from B in Ember

The List

We’ll have two models, called Apple and Orange

Each has their own route, controller, view, and template

This is just for the simplest case

Page 9: How to Call A from B in Ember

When I’m AppleRoute…Apple (the model)

this.modelFor(‘apple’)

OrangeRoute

this.get(‘router’).getHandler(‘orange’)

AppleController

this.controllerFor(‘apple’)

AppleView - no idea

Apple Template - no idea

Page 10: How to Call A from B in Ember

When I’m AppleController…Apple (the model)

this.get(‘content’) (if it’s an Ember.ObjectController)

AppleRoute

this.get(‘target’) (if you’re currently on that route)

OrangeController

needs: [‘orange’] (in the root of AppleController)

this.get(‘controllers.orange’)

AppleView - no idea

Apple Template - no idea

Page 11: How to Call A from B in Ember

When I’m 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 you’re currently on that route)

AppleController

this.get(‘controller’)

OrangeView - no idea

Apple Template

this.get(‘template’) (for the handlebars function, but you wouldn’t touch that much)

this.get(‘element’) (for the DOM element)

Page 12: How to Call A from B in Ember

When I’m 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 you’re currently on that route)

AppleController

this.get(‘controller’)

AppleView

this.get(‘view’)

Orange Template - no idea

Page 13: How to Call A from B in Ember

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’)

Page 14: How to Call A from B in Ember

THANK YOU

THESE SLIDES WILL BE ONLINE SOMEWHERE

Page 15: How to Call A from B in Ember

THANK YOU

THESE SLIDES WILL BE ONLINE SOMEWHERE

obligatory tech talk meme photo -->