Slide 1

Slide 1 text

Ember.js & Ember-CLI Iheanyi Ekechukwu @kwuchu IBM Watson Life http://iheanyi.com

Slide 2

Slide 2 text

What is Ember?

Slide 3

Slide 3 text

A framework for creating ambitious web applications.

Slide 4

Slide 4 text

Why Ember?

Slide 5

Slide 5 text

As a Designer

Slide 6

Slide 6 text

I can make ambitious UIs. Really ambitious.

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Let's see another "ambitious" UI

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

How is this possible?

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Just kidding. Ember's Router and Nested Routes = <3 Data, URLs, UI, and State are all in sync.

Slide 14

Slide 14 text

import Ember from 'ember'; import config from './config/environment'; var Router = Ember.Router.extend({ location: config.locationType }); export default Router.map(function() { this.route('contacts', function() { this.route('show', {path: '/:id'}); }); });

Slide 15

Slide 15 text

URL:t URL: /contacts/1

Slide 16

Slide 16 text

Animations help take your UI to the next level.

Slide 17

Slide 17 text

Liquid Fire (https://github.com/ef4/liquid- fire)

Slide 18

Slide 18 text

Gif of Barbr here.

Slide 19

Slide 19 text

Wow, that must've been really complicated.

Slide 20

Slide 20 text

ember install liquid-fire

Slide 21

Slide 21 text

{{liquid-outlet}} # previously {{outlet}}

Slide 22

Slide 22 text

export default function() { this.transition( this.fromRoute('index'), this.use('toLeft'), this.reverse('toRight') ); this.transition( this.fromRoute('barbershops'), this.use('toLeft'), this.reverse('toRight') ); }

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

As a Developer

Slide 25

Slide 25 text

Convention over Configuration.

Slide 26

Slide 26 text

HTMLBars for Templating

Slide 27

Slide 27 text

Simple Template Action Handling by Components, Controllers, and Routes

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Sign In With Facebook {{/if}} {{#if session.isAuthenticated}} Logout {{else}}

Slide 30

Slide 30 text

import Ember from 'ember'; import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin'; export default Ember.Controller.extend(LoginControllerMixin, { authenticator: 'simple-auth-authenticator:torii', actions: { signIn: function() { var controller = this.controllerFor('index'); var session = this.get('session'); session.authenticate('simple-auth-authenticator:torii', 'facebook- connect').then(function() { controller.transitionToRoute('likes'); }); } });

Slide 31

Slide 31 text

Ember-Data

Slide 32

Slide 32 text

Let's see a quick example/overview.

Slide 33

Slide 33 text

ember generate adapter application create app/adapters/application create tests/unit/adapters/application-test.js

Slide 34

Slide 34 text

import DS from 'ember-data'; export default DS.RESTAdapter.extend({ namespace: 'api' });

Slide 35

Slide 35 text

ember generate model contact firstName:string lastName:string \ email:string avatar:string description:string create app/models/contact.js create tests/unit/models/contacts-test.js

Slide 36

Slide 36 text

// app/models/contact.js import DS from 'ember-data'; export default DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), avatar: DS.attr('string'), email: DS.attr('string'), description: DS.attr('string') });

Slide 37

Slide 37 text

ember generate route contacts create app/routes/contacts.js create tests/unit/routes/contacts-test.js

Slide 38

Slide 38 text

// app/routes/contacts.js import Ember from 'ember'; export default Ember.Route.extend({ });

Slide 39

Slide 39 text

// app/routes/contacts.js import Ember from 'ember'; export default Ember.Route.extend({ model() { return this.store.find('contact'); } });

Slide 40

Slide 40 text

this.store.find('contact');

Slide 41

Slide 41 text

this.store.find('contact', params.id);

Slide 42

Slide 42 text

this.store.createRecord('contact', data);

Slide 43

Slide 43 text

this.store.query('contact', query);

Slide 44

Slide 44 text

this.store.find('contact', params.id).then(function(contact) { contact.set('firstName', 'Iheanyi'); contact.save(); }); }

Slide 45

Slide 45 text

contact.deleteRecord();

Slide 46

Slide 46 text

contact.destroyRecord();

Slide 47

Slide 47 text

And that's not all...

Slide 48

Slide 48 text

this.store.filter('contact', function(contact) { return contact.get('firstName')[0] === "A"; });

Slide 49

Slide 49 text

Computed Properties

Slide 50

Slide 50 text

// app/models/contact.js import DS from 'ember-data'; export default DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), avatar: DS.attr('string'), email: DS.attr('string'), description: DS.attr('string'), fullName: Ember.computed('firstName', 'lastName', function(key, value) { return `${this.get('firstName')} ${this.get('lastName')}`; }) });

Slide 51

Slide 51 text

this.store.createRecord('contact', {firstName: "Iheanyi", lastName: "Ekechukwu"}).then(function(contact) { contact.get('fullName'); // Iheanyi Ekechukwu });

Slide 52

Slide 52 text

import Ember from 'ember'; export default Ember.Controller.extend({ sortProperties: ['fullName'], sortedContacts: Ember.computed.sort('model', 'sortProperties') });

Slide 53

Slide 53 text

Bound Attributes

Slide 54

Slide 54 text

E-Mail: {{model.email}}

Slide 55

Slide 55 text

Components for Reusability

Slide 56

Slide 56 text

ember generate component contact-card create app/components/contact-card.js create app/templates/components/contact-card.hbs installing component-test create tests/integration/components/contact-card-test.js

Slide 57

Slide 57 text

{{contact.fullName}}

{{contact.description}}

{{yield}}

Slide 58

Slide 58 text

{{contact-card contact=model}}

Slide 59

Slide 59 text

Community

Slide 60

Slide 60 text

Community

Slide 61

Slide 61 text

Ember Community Slack Channel (https://ember-community- slackin.herokuapp.com/)

Slide 62

Slide 62 text

Tooling

Slide 63

Slide 63 text

Ember-Inspector (https://github.com/ emberjs/ember-inspector)

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

Let's talk more about Ember- CLI (www.ember-cli.com)

Slide 67

Slide 67 text

What's the hype around Ember-CLI?

Slide 68

Slide 68 text

ES6 via Esperanto

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

But Iheanyi, what about third party libraries or preprocessors?

Slide 71

Slide 71 text

bower install bootstrap --save

Slide 72

Slide 72 text

// ember-cli-build.js var EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function(defaults) { var app = new EmberApp(defaults, { // Add options here }); app.import('bower_components/bootstrap/dist/css/bootstrap.css'); return app.toTree(); };

Slide 73

Slide 73 text

Cool! What about for JavaScript libraries?

Slide 74

Slide 74 text

bower install moment --save

Slide 75

Slide 75 text

// ember-cli-build.js var EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function(defaults) { var app = new EmberApp(defaults, { // Add options here }); ... app.import('bower_components/moment/moment.js'); return app.toTree(); };

Slide 76

Slide 76 text

And preprocessors?

Slide 77

Slide 77 text

ember install ember-cli-sass mv app/styles/app.css app/styles/app.scss

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

RemEMBER those conventions?

Slide 80

Slide 80 text

Generators

Slide 81

Slide 81 text

ember generate [options] [properties]

Slide 82

Slide 82 text

acceptance-test adapter adapter-test addon addon-import app blueprint component component-addon component-test controller controller-test helper helper-test http-mock http-proxy in-repo-addon initializer initializer-test lib mixin mixin-test model model-test resource route route-test serializer serializer-test server service service-test template test-helper transform transform-test util util-test view view-test

Slide 83

Slide 83 text

Addons

Slide 84

Slide 84 text

Ember Observer (http://emberobserver.com/)

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

There's an addon for almost everything.

Slide 87

Slide 87 text

User Authentication?

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

Mock Data/API Services?

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

// app/mirage/factories/contact.js import Mirage, {faker} from 'ember-cli-mirage'; export default Mirage.Factory.extend({ firstName: faker.name.firstName, lastName: faker.name.lastName, email: faker.internet.email, avatar: faker.internet.avatar, description: faker.lorem.paragraphs(4) });

Slide 92

Slide 92 text

// app/mirage/config.js export default function() { this.namespace = '/api'; this.get('/contacts', function(db, request) { return {contacts: db.contacts}; }); this.get('/contacts/:id', function(db, request) { return {contacts: db.contacts.find(request.params.id)}; }); }

Slide 93

Slide 93 text

// app/mirage/scenarios/default.js export default function( server ) { // Seed your development database using your factories. This // data will not be loaded in your tests. server.createList('contact', 10); }

Slide 94

Slide 94 text

// app/routes/contacts.js import Ember from 'ember'; export default Ember.Route.extend({ model() { return this.store.find('contact'); } });

Slide 95

Slide 95 text

Contacts Route

    {{#each sortedContacts as |contact|}}
  • {{#link-to 'contacts.show' contact.id}}
    {{contact.fullName}}
    {{/link-to}}
  • {{/each}}
{{outlet}}

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

Testing

Slide 98

Slide 98 text

QUnit

Slide 99

Slide 99 text

ember generate acceptance-test list-contacts

Slide 100

Slide 100 text

import Ember from 'ember'; import { module, test } from 'qunit'; import startApp from 'front-porch-demo/tests/helpers/start-app'; var application; module('Acceptance: ListContacts', { beforeEach: function() { application = startApp(); }, afterEach: function() { Ember.run(application, 'destroy'); } }); test('visiting /contacts should list 10 contacts', function(assert) { server.createList('contact', 10); // Thanks Mirage! visit('/contacts'); andThen(function() { assert.equal(find('.contacts__list__item').length, 10); }); });

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

Like Mocha? No problem.

Slide 103

Slide 103 text

ember install ember-cli-mocha

Slide 104

Slide 104 text

/* jshint expr:true */ import { describe, it, beforeEach, afterEach } from 'mocha'; import { expect } from 'chai'; import Ember from 'ember'; import startApp from '../helpers/start-app'; describe('Acceptance: ListContacts', function() { var application; beforeEach(function() { application = startApp(); }); afterEach(function() { Ember.run(application, 'destroy'); }); it('can visit /contacts and see 10 contacts', function() { server.createList('contact', 10); visit('/contacts'); andThen(function() { expect(currentPath()).to.equal('contacts.index'); expect(find('.contacts__list__item').length).to.equal(10); }); }); });

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

Just wanna test from the CLI? Ember-CLI has your back.

Slide 107

Slide 107 text

ember test

Slide 108

Slide 108 text

ember test ... 1..32 # tests 32 # pass 24 # fail 8

Slide 109

Slide 109 text

ember test --server

Slide 110

Slide 110 text

Deploying

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

Adapters for Azure, Redis, and S3

Slide 113

Slide 113 text

npm install ember-cli-deploy --save-dev

Slide 114

Slide 114 text

ember deploy --environment production

Slide 115

Slide 115 text

Divshot.io

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

npm install --save-dev ember-cli-divshot

Slide 118

Slide 118 text

ember generate divshot

Slide 119

Slide 119 text

ember divshot push

Slide 120

Slide 120 text

Trying to deploy to Heroku or IBM Bluemix?

Slide 121

Slide 121 text

There's a buildpack for that. (https://github.com/tonycoco/ heroku-buildpack-ember-cli)

Slide 122

Slide 122 text

heroku create --buildpack https://github.com/tonycoco/heroku-buildpack-ember-cli.git

Slide 123

Slide 123 text

cf push ember_contacts_demo -b \ https://github.com/tonycoco/heroku-buildpack-ember-cli.git

Slide 124

Slide 124 text

All of these deployment methods run the Ember Build command prior to deployment.

Slide 125

Slide 125 text

Getting started with Ember-CLI is easy enough.

Slide 126

Slide 126 text

npm install -g ember-cli

Slide 127

Slide 127 text

ember new ember-demo-project

Slide 128

Slide 128 text

Now you're ready to dive in.

Slide 129

Slide 129 text

Links and Thanks http://emberjs.com http://ember-cli.com Brandon (@tehviking) Stanley (@fivetanley) Lon (@lawnsea) Chan (@chantastic) Ember Core Team And everybody else.

Slide 130

Slide 130 text

Thank You. @kwuchu http://iheanyi.com