Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ember.js and Ember-CLI
Search
Iheanyi Ekechukwu
August 18, 2015
Programming
5
530
Ember.js and Ember-CLI
Sldies from my talk on Ember.js and Ember-CLI from the Austin JavaScript meetup.
Iheanyi Ekechukwu
August 18, 2015
Tweet
Share
More Decks by Iheanyi Ekechukwu
See All by Iheanyi Ekechukwu
Building a Canary Testing Framework
iheanyi
0
480
gRPC and Protobufs - JSCamp Romania
iheanyi
0
260
Ember.js, DevOps, and You - NPM Camp 2016
iheanyi
0
380
Ember.js, DevOps, and You - MadisonRuby 2016
iheanyi
0
220
Ember.js, DevOps, and You - Wicked Good Ember 2016
iheanyi
1
750
Intro to Ember.js and Ember-CLI - ThunderPlainsConf 2015
iheanyi
0
240
Intro to Ember.js and Ember-CLI - Front Porch 2015
iheanyi
0
450
Other Decks in Programming
See All in Programming
Tuning GraphQL on Rails
pyama86
2
1.2k
イベント駆動で成長して委員会
happymana
1
270
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
1.5k
Ethereum_.pdf
nekomatu
0
370
JavaでLチカしたい! / JJUG CCC 2024 Fall LT
nhayato
0
120
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
790
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
220
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
280
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
190
Hotwire or React? ~Reactの録画機能をHotwireに置き換えて得られた知見~ / hotwire_or_react
harunatsujita
8
5.1k
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
160
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
4
580
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
GraphQLとの向き合い方2022年版
quramy
43
13k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
820
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.8k
Speed Design
sergeychernyshev
24
600
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
15
2k
Transcript
Ember.js & Ember-CLI Iheanyi Ekechukwu @kwuchu IBM Watson Life http://iheanyi.com
What is Ember?
A framework for creating ambitious web applications.
Why Ember?
As a Designer
I can make ambitious UIs. Really ambitious.
None
None
Let's see another "ambitious" UI
None
How is this possible?
None
Just kidding. Ember's Router and Nested Routes = <3 Data,
URLs, UI, and State are all in sync.
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'}); }); });
URL:t URL: /contacts/1
Animations help take your UI to the next level.
Liquid Fire (https://github.com/ef4/liquid- fire)
Gif of Barbr here.
Wow, that must've been really complicated.
ember install liquid-fire
{{liquid-outlet}} # previously {{outlet}} <nav class="navbar navbar-default"> <div class="container"> <div
class="navbar-header"> {{#link-to 'index' class="navbar-brand"}} Barber Application {{/link-to}} </div> <ul class="nav navbar-nav"> <li>{{link-to 'Barbershops' 'barbershops'}}</li> </ul> <ul class="nav navbar-nav navbar-right"> {{#if this.currentUser}} <li><p class="navbar-text">Signed in as {{currentUser.username}}</p></li> <li><a class="logout-link" {{action 'logout'}}>Logout</a></li> {{else}} <li>{{link-to "Login" 'login'}}</li> <li>{{link-to 'Register' 'users.new'}}</li> {{/if}} </ul> </div> </nav>
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') ); }
None
As a Developer
Convention over Configuration.
HTMLBars for Templating
Simple Template Action Handling by Components, Controllers, and Routes
None
<a href="#" class="btn btn-custom btn-social btn-md btn-facebook" {{action 'signIn'}}> <i
class="fa fa-facebook"></i> Sign In With Facebook </a> {{/if}} {{#if session.isAuthenticated}} <a href="#" class="btn btn-custom btn-social btn-md btn-facebook" {{action 'invalidateSession'}}> <i class="fa fa-facebook"></i> Logout </a> {{else}}
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'); }); } });
Ember-Data
Let's see a quick example/overview.
ember generate adapter application create app/adapters/application create tests/unit/adapters/application-test.js
import DS from 'ember-data'; export default DS.RESTAdapter.extend({ namespace: 'api' });
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
// 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') });
ember generate route contacts create app/routes/contacts.js create tests/unit/routes/contacts-test.js
// app/routes/contacts.js import Ember from 'ember'; export default Ember.Route.extend({ });
// app/routes/contacts.js import Ember from 'ember'; export default Ember.Route.extend({ model()
{ return this.store.find('contact'); } });
this.store.find('contact');
this.store.find('contact', params.id);
this.store.createRecord('contact', data);
this.store.query('contact', query);
this.store.find('contact', params.id).then(function(contact) { contact.set('firstName', 'Iheanyi'); contact.save(); }); }
contact.deleteRecord();
contact.destroyRecord();
And that's not all...
this.store.filter('contact', function(contact) { return contact.get('firstName')[0] === "A"; });
Computed Properties
// 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')}`; }) });
this.store.createRecord('contact', {firstName: "Iheanyi", lastName: "Ekechukwu"}).then(function(contact) { contact.get('fullName'); // Iheanyi Ekechukwu
});
import Ember from 'ember'; export default Ember.Controller.extend({ sortProperties: ['fullName'], sortedContacts:
Ember.computed.sort('model', 'sortProperties') });
Bound Attributes
<p>E-Mail: <a href="mailto:{{model.email}}">{{model.email}}</a></p>
Components for Reusability
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
<div class="contact-card"> <h5>{{contact.fullName}}</h5> <p>{{contact.description}}</p> </div> {{yield}}
{{contact-card contact=model}}
Community
Community
Ember Community Slack Channel (https://ember-community- slackin.herokuapp.com/)
Tooling
Ember-Inspector (https://github.com/ emberjs/ember-inspector)
None
None
Let's talk more about Ember- CLI (www.ember-cli.com)
What's the hype around Ember-CLI?
ES6 via Esperanto
None
But Iheanyi, what about third party libraries or preprocessors?
bower install bootstrap --save
// 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(); };
Cool! What about for JavaScript libraries?
bower install moment --save
// 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(); };
And preprocessors?
ember install ember-cli-sass mv app/styles/app.css app/styles/app.scss
None
RemEMBER those conventions?
Generators
ember generate [options] <type> <name> [properties]
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
Addons
Ember Observer (http://emberobserver.com/)
None
There's an addon for almost everything.
User Authentication?
None
Mock Data/API Services?
None
// 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) });
// 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)}; }); }
// 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); }
// app/routes/contacts.js import Ember from 'ember'; export default Ember.Route.extend({ model()
{ return this.store.find('contact'); } });
<div class="container"> <h1>Contacts Route</h1> <div class="contacts__sidebar"> <ul class="contacts__list"> {{#each sortedContacts
as |contact|}} <li class="contacts__list__item"> {{#link-to 'contacts.show' contact.id}} <div class="contacts-list-item-detail"> <img class="contact__sidebar__picture" src={{contact.avatar}}> <span class="contact__sidebar__name">{{contact.fullName}}</span> </div> {{/link-to}} </li> {{/each}} </ul> </div> <div class="contacts__detail"> {{outlet}} </div> </div>
None
Testing
QUnit
ember generate acceptance-test list-contacts
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); }); });
None
Like Mocha? No problem.
ember install ember-cli-mocha
/* 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); }); }); });
None
Just wanna test from the CLI? Ember-CLI has your back.
ember test
ember test ... 1..32 # tests 32 # pass 24
# fail 8
ember test --server
Deploying
None
Adapters for Azure, Redis, and S3
npm install ember-cli-deploy --save-dev
ember deploy --environment production
Divshot.io
None
npm install --save-dev ember-cli-divshot
ember generate divshot
ember divshot push
Trying to deploy to Heroku or IBM Bluemix?
There's a buildpack for that. (https://github.com/tonycoco/ heroku-buildpack-ember-cli)
heroku create --buildpack https://github.com/tonycoco/heroku-buildpack-ember-cli.git
cf push ember_contacts_demo -b \ https://github.com/tonycoco/heroku-buildpack-ember-cli.git
All of these deployment methods run the Ember Build command
prior to deployment.
Getting started with Ember-CLI is easy enough.
npm install -g ember-cli
ember new ember-demo-project
Now you're ready to dive in.
Links and Thanks http://emberjs.com http://ember-cli.com Brandon (@tehviking) Stanley (@fivetanley) Lon
(@lawnsea) Chan (@chantastic) Ember Core Team And everybody else.
Thank You. @kwuchu http://iheanyi.com