Slide 1

Slide 1 text

Ember Views June 2012 Ray Cohen Developer @ Boxee

Slide 2

Slide 2 text

from

Slide 3

Slide 3 text

Basics

Slide 4

Slide 4 text

Basics

Slide 5

Slide 5 text

Same as

Slide 6

Slide 6 text

Basics • A template is a function that builds a string • Handlebars compiles strings to templates • templateName is a key into Ember.TEMPLATES

Slide 7

Slide 7 text

Binding values to DOM

Slide 8

Slide 8 text

Binding values to DOM

Slide 9

Slide 9 text

{{bound}} and {{unbound}}

Slide 10

Slide 10 text

Escaped by default

Slide 11

Slide 11 text

Binding element properties Need another way FAIL

Slide 12

Slide 12 text

{{bindAttr}} helper

Slide 13

Slide 13 text

Helpers • Functions invoked by {{fn-name params}} • Invoked during view render • Output a string to the buffer • Can set up property observers

Slide 14

Slide 14 text

The {{#if}} helper `#` before helper name: takes a block

Slide 15

Slide 15 text

How {{#if}} works • Create metamorph view • Observe App.loggedIn • On change, switch template Blocks become templates

Slide 16

Slide 16 text

The {{view}} helper

Slide 17

Slide 17 text

The {{#view}} helper

Slide 18

Slide 18 text

The {{#view}} helper Behind the scenes

Slide 19

Slide 19 text

Ember.ContainerView • Templates can’t always describe all UI • Sometimes more flexibility is required • ContainerView holds other view instances, allows code to add, remove, reorder • set currentView property • or manage childViews array

Slide 20

Slide 20 text

Something is missing

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

context keywords so far we’ve been dodging this topic with globals like App.team

Slide 23

Slide 23 text

Old way: view is context TL;DR

Slide 24

Slide 24 text

view keyword 0.9 1.0 beta

Slide 25

Slide 25 text

Setting context: {{#with}}

Slide 26

Slide 26 text

Setting context: {{#each}}

Slide 27

Slide 27 text

Setting context: {{view}} When?

Slide 28

Slide 28 text

Controllers 1.0 beta

Slide 29

Slide 29 text

Setting context: {{view}} If available, use controller as context otherwise, use existing context.

Slide 30

Slide 30 text

Result • Controller is context for a chunk of DOM • Controller is good place to have properties that many views access • Reduces need to bind lots of values to the views themselves • Moving things around in templates is easier

Slide 31

Slide 31 text

Setting keywords

Slide 32

Slide 32 text

Setting keywords

Slide 33

Slide 33 text

Creating helpers • Main issue is having bindings work within your helper’s output • Easiest path: call one of the other helpers from your helper after some setup • Future: easier ability to bind some types of helpers (see PR 615)

Slide 34

Slide 34 text

Example: {{outlet}}

Slide 35

Slide 35 text

Example: {{outlet}}

Slide 36

Slide 36 text

Event Delegation & Lifecycle hooks

Slide 37

Slide 37 text

Event Delegation

Slide 38

Slide 38 text

Event Delegation rootElement.delegate(...)

Slide 39

Slide 39 text

didInsert and willDestroy jQuery!

Slide 40

Slide 40 text

Mixins are _super()

Slide 41

Slide 41 text

Example Mixin

Slide 42

Slide 42 text

Example Mixin

Slide 43

Slide 43 text

Infinite Scroll don’t forget to call _super()

Slide 44

Slide 44 text

Resources • emberjs.com/guides/ • emberist.com/ - Peter Wagenet’s blog • IRC - #emberjs on Freenode • bring your jsfiddle!

Slide 45

Slide 45 text

Thanks! @raycohen