ember.js for big profit

55

Upload: codecore

Post on 17-May-2015

284 views

Category:

Design


4 download

DESCRIPTION

Paul Ruescher's Slide deck from the first Ember.js Meetup - Vancouver. (#EmberYVR) May 14th 2014 at CodeCore Bootcamp. Ember.js is a framework for creating ambitious web applications. What does an "ambitious web application" even mean? What if I’m not working on an ambitious web application? In this talk, Paul will put you through an Ember Bootcamp on your way to $$$.

TRANSCRIPT

Page 2: Ember.js for Big Profit
Page 4: Ember.js for Big Profit

Ember.js For Big $$$

Page 5: Ember.js for Big Profit

What This Talk Isn’tEmber vs Angular

Page 6: Ember.js for Big Profit

What This Talk Is

Page 7: Ember.js for Big Profit

Performance!

Page 8: Ember.js for Big Profit

Caching

Page 9: Ember.js for Big Profit

More requests per second

Page 10: Ember.js for Big Profit

Lower latency

Page 11: Ember.js for Big Profit

Networks

Page 12: Ember.js for Big Profit

Native Apps

Page 13: Ember.js for Big Profit

Single-Page Apps

Page 14: Ember.js for Big Profit

Compared to server-side

Single-Page Apps

Page 15: Ember.js for Big Profit

Cons

Single-Page Apps

Page 16: Ember.js for Big Profit

Pros

Single-Page Apps

Page 17: Ember.js for Big Profit

Really?

The URL

Page 18: Ember.js for Big Profit

Document Linking

Page 19: Ember.js for Big Profit

Manages State

Page 20: Ember.js for Big Profit
Page 21: Ember.js for Big Profit

What is Ember?

The Basics

Page 22: Ember.js for Big Profit

What Does Ember Do?

● History management (URL / Router)

● Developer ergonomics

● Easy, fast, two-way binding

● Views built in HTML (Handlebars)

● Ember data

Page 23: Ember.js for Big Profit

Developer ergonomics

Page 24: Ember.js for Big Profit

Convention > Configuration

this.resource('person', { path: '/person'});

App.Person = Ember.Object.extend();

App.PersonRoute = Ember.Route.extend();

App.PersonController = Ember.ObjectController.extend();

App.PersonView = Ember.View.extend();

person.hbs

Page 25: Ember.js for Big Profit

One Source of Truth

Page 26: Ember.js for Big Profit

One Source of Truth

function ajaxCall() {

$.ajax({

url: 'http://example/com/api-endpoint',

})

.done(function(data) {

$('#some-element').append('<div class="child-element-name"'> + data.name + '</div><div class="child-element-count">' + data.count + '</div>');

});

}

Page 27: Ember.js for Big Profit

“A Sprinkling of JavaScript”

Page 28: Ember.js for Big Profit

The BasicsMVC

Page 29: Ember.js for Big Profit

● Wikipedia: consists of application data, business rules, logic and functions

● Ember: properties and behaviour of data presented to user

● Ember: anything requiring persistence should be in a model

Model

Page 30: Ember.js for Big Profit

View

● Wikipedia: a view can be any representation of information

● Ember: handles complex user interactions

● essentially any of the UI elements you see on the screen

Page 31: Ember.js for Big Profit

Controller

● Wikipedia: accepts input and converts it to commands for the model or view

● Ember: decorate your models with display logic

● Ember: generally handles state that doesn’t need to be persisted

Page 32: Ember.js for Big Profit

MVC/post → show all posts/post/new → create new post/post/1 → show post with ID of 1/post/1/edit → edit post with ID of 1

Page 33: Ember.js for Big Profit

ModelApp.Person = Ember.Object.create({

firstName: null,

lastName: null

});

var person = App.Person.create({

firstName: ‘Paul’,

lastName: ‘Ruescher’

});

Page 34: Ember.js for Big Profit

View

● handlebars

● bound properties

Coming Soon: http://talks.erikbryn.com/htmlbars/#

Page 35: Ember.js for Big Profit

View

App.PersonView = Ember.View.extend({

classNamesBindings: ['active', 'selected'],

click: function() {

this.get('controller').send('clearName');

}

});

Page 36: Ember.js for Big Profit

View - Template

<h2>{{title}}</h2>

{{#each item in controller}}

{{input value=item.firstName}}

{{input value=item.lastName}}

<h2>{{item.fullName}}</h2>

{{/each}}

Page 37: Ember.js for Big Profit

ControllerApp.Person = Ember.Object.create({

firstName: null,

lastName: null

});

App.PersonController = Ember.ObjectController.extend({

fullName: function() {

return this.get('firstName') + ' ' + this.get('lastName');

}.property('firstName', 'lastName');

});

Page 38: Ember.js for Big Profit

ControllerApp.PersonController = Ember.ObjectController.extend({

actions: {

clearName: function() {

this.setProperties({

firstName: null,

lastName: null

});

}

}

});

Page 39: Ember.js for Big Profit

MVC + R

Page 40: Ember.js for Big Profit

● helps manage state as users interact with your app

● the router is responsible for displaying templates and loading data

● does this by matching the URL to the routes you define

Router

Page 41: Ember.js for Big Profit

Router/post → show all posts/post/new → create new post/post/1 → show post with ID of 1/post/1/edit → edit post with ID of 1

Page 42: Ember.js for Big Profit

Router

App.Router.map(function(){

this.resource('posts', { path: '/post/' }, function() {

this.route('new');

this.resource('post', { path: '/:post_id' }, function() {

this.route('edit');

});

});

});

Page 43: Ember.js for Big Profit
Page 44: Ember.js for Big Profit

http://emberjs.jsbin.com/puhorage/2/edit

Putting It All Together

Page 45: Ember.js for Big Profit

Ember Things You Should Know

Page 46: Ember.js for Big Profit

http://emberjs.com/guides

The Guides

Page 47: Ember.js for Big Profit

Promises

Page 48: Ember.js for Big Profit

Components

Page 49: Ember.js for Big Profit

http://emberjs.com/guides/testing/

Testing

Page 50: Ember.js for Big Profit

Building

Page 51: Ember.js for Big Profit

https://github.com/yeoman/generator-ember

Yeoman Generator

Page 52: Ember.js for Big Profit

https://github.com/emberjs/ember-rails

Ember Rails

Page 53: Ember.js for Big Profit

https://github.com/stefanpenner/ember-cli

EAK and Ember CLI

Page 54: Ember.js for Big Profit

http://emberjs.com/community/

Super Cool Code Pals

Page 55: Ember.js for Big Profit

@[email protected]

Thanks!