Workshop 16: EmberJS Parte I

Visual Engineering
Visual EngineeringVisual Engineering
Raúl Delgado & Andrés Lamilla
Front End Workshops
EmberJS General Overview
rdelgado@visual-engin.com
alamilla@visual-engin.com
A framework for creating ambitious
web applications.
● Focus on ambitious web applications: applications that look and act
like desktop applications, but happen to be delivered via web
technologies
● More productive out of the box: provide a complete development
stack to make the developer productive immediately. (Ember CLI,
application structure, thousands addons).
● Stability without stagnation: backward compatibility is important and
can be maintained while still innovating and evolving the framework.
● Future web standards foresight: pioneer of many standards around
Javascript and the web. (promises, web components and ES6 syntax)
Philosophy
● Routes: the state of an application is represented by a URL
● Models: data associated with the current state of the application
● Templates: HTMLBars templating language. (Handlebars
variation)
● Components: custom HTML tag
● Services: singleton objects to hold long-lived data such as user
sessions
Five essential Concepts
Big Picture
● In December 2011, the SproutCore 2.0 framework was renamed to Ember.js
● The framework was created by Yehuda Katz, a member of the jQuery, Ruby
on Rails and SproutCore core teams
● Ember follows a six-week release cycle. Every six weeks a new release is
made available, and at the same time a beta for the next release is also
published
● Ember follows the semantic versioning convention. This means that breaking
changes are only introduced at major version numbers such as 1.0, 2.0 etc.
● Ember 2.0 was released August 13, 2015. Introduction of the Glimmer
rendering engine
● It follows the Convention over configuration design paradigm
● Stable release 2.4.3 / March 17, 2016
Facts
Ember cli
● Strong conventional project structure
● Powerful addon system for extension
● Uses babel, which turns ES2015 module syntax into AMD (RequireJS-esq)
modules.
● Use QUnit and Ember QUnit by default. But, you are free to use other options
such as Mocha and Ember Mocha.
● Use Bower, for front-end dependencies and npm, for managing internal
dependencies
● Is configurable via a file named .ember-cli
Ember cli
Has support for:
● Handlebars
● HTMLBars
● Emblem
● LESS
● Sass
● Compass
● Stylus
● CoffeeScript
● EmberScript
● Minified JS & CSS
Ember cli
Commands:
● ember
● ember new <app-name>
● ember init
● ember build
● ember server
● ember generate <generator-name> <options>
● ember help generate
● ember destroy <generator-name> <options>
● ember test
● ember install <addon-name>
Ember cli
npm install -g ember-cli@2.4
ember new ember-quickstart
cd ember-quickstart
ember serve
Livereload server on http://localhost:49152
Serving on http://localhost:4200/
ember generate route scientists
installing route
create app/routes/scientists.js
create app/templates/scientists.hbs
updating router
add route scientists
installing route-test
create tests/unit/routes/scientists-test.js
ember build --env production
Ember cli
ember install ember-cli-sass
ember install ember-cli-bootstrap-sassy
mv app/styles/app.css app/styles/app.scss
echo '@import "bootstrap";' > app/styles/app.scss
Ember cli
Ember.object
Ember implements its own object system. The base object is Ember.Object.
All of the other objects in Ember extend Ember.Object.
Ember.Object can observe properties change.
This simple architectural decision is responsible for much of the consistency
across Ember. Every Ember object can observe the properties of other
objects, bind their properties to the properties of other objects, specify and
update computed properties, and much more.
This gives enormous power and flexibility !
Ember.object
Ember.object vs JS object
Defining new Ember Class:
Ember.object
Properties:
person1 = Person.extend({
firstName: “John”,
lastName: “McClaine”,
fullName(): {
let fullName = this.firstName + ‘ ’ + this.lastName;
alert(`my name is ${fullName} !`)
}
})
person1.get(‘firstName’) //John
person1.get(‘lastName’) //McClane
person1.fullName()
//my name is John Mclane !
Person = Ember.Object.extend()
user = Person.create()
Observers:
Ember.object
Person = Ember.Object.extend({
firstName: null,
lastName: null,
fullName: Ember.computed( 'firstName', 'lastName', function() {
return `${this.get('firstName')} ${this.get('lastName')}`;
}),
fullNameChanged: Ember.observer( 'fullName', () => {
// deal with the change
console.log(`fullName changed to: ${this.get('fullName')}`);
})
})
var person = Person.create({
firstName : Harry,
lastName : ‘Stamper’
})
person.get(‘fullName’) // Harry Stamper
person.set(‘firstName’, “Grace”)
// fullName changet to: Grace Stamper
Models
The models are objects that represent the underlying data that the application
presents the user. Different applications have very different models,
depending on what are the problems they are trying to solve.
You can create a model with the command:
This will generate:
Models
$ ember generate model person
Models
Defining attributes:
To define attributes to our model, we have four methods:
- Attr
- hasMany
- belonsTo
- normalizeModelName
attr:
Models
Relationship methods: hasMany & belongsTo:
One-to-one:
One-to-many:
Many-to-many:
Routing
Ember is URL-driven so it always starts in the
URL. In the example, our router has the
following definition:
Routing
An instance of the Route invoke the model() method where we turn the model.
Here it looks like a dummy object is returned:
Once model() has been returned, the
renderComponent() method call
ItemDisplayComponent model.
Not only push data paths. They can also
receive actions.
Actions are sent from components or other
routes, so that the logic transitions involving
URL or another route-level issue.
Routing
Routing
What’s going on here?
1. The Router parses the /items/2 URL and dispatches
control to a matching route: ItemRoute with a
parameter item_id=2
2. ItemRoute invokes its model() hook, in which our
app returns a model (Item with id=2) fetched via a
service
3. renderComponent() is then run to render the
component ItemDisplayComponent, passing it the
resolved model Item
4. ItemDisplayComponent is responsible for the user
interface: rendering/updating the DOM, and handling
browser events
The application route is entered when your app first boots up. Like other routes, it will load a
template with the same name (application in this case) by default. You should put your header,
footer, and any other decorative content here. All other routes will render their templates into the
application.hbs template's {{outlet}}.
This route is part of every application, so you don't need to specify it in your app/router.js.
Routing
The application route:
Index Routes:
At every level of nesting (including the top level),
Ember automatically provides a route for the /
path named index.
Templates
app/helpers/sum.js
export function sum(params) {
return params.reduce((a, b) => {
return a + b;
});
};
export default Ember.Helper.helper(sum);
Templates
<p>Total: {{sum 1 2 3}}</p>
{{sum (multiply 2 4) 2}}
<div>
{{if isFast "I am fast" "I am slow"}}
</div>
Templates
<div>
{{if isFast (if isFueled "zoooom")}}
</div>
{{#if isAtWork}}
Ship that code!
{{else if isReading}}
You can finish War and Peace eventually...
{{/if}}
{{#each people as |person|}}
Hello, {{person.name}}!
{{else}}
Sorry, nobody is here.
{{/each}}
Templates
<ul>
{{#each people as |person index|}}
<li>Hello, {{person.name}}! You're number {{index}} in line</li>
{{/each}}
</ul>
/app/components/store-categories.js
export default Ember.Component.extend({
willRender() {
this.set('categories', {
'Bourbons': ['Bulleit', 'Four Roses', 'Woodford Reserve'],
'Ryes': ['WhistlePig', 'High West']
});
}
});
Templates
/app/templates/components/store-categories.hbs
<ul>
{{#each-in categories as |category products|}}
<li>{{category}}
<ol>
{{#each products as |product|}}
<li>{{product}}</li>
{{/each}}
</ol>
</li>
{{/each-in}}
</ul>
<ul>
<li>Bourbons
<ol>
<li>Bulleit</li>
<li>Four Roses</li>
<li>Woodford Reserve</li>
</ol>
</li>
<li>Ryes
<ol>
<li>WhistlePig</li>
<li>High West</li>
</ol>
</li>
</ul>
/app/components/store-categories.js
export default Ember.Component.extend({
willRender() {
this.set('categories', {
'Bourbons': ['Bulleit', 'Four Roses', 'Woodford Reserve'],
'Ryes': ['WhistlePig', 'High West']
});
},
actions: {
addCategory(category) {
let categories = this.get('categories');
categories[category] = [ ];
// A manual re-render causes the DOM to be updated
this.rerender();
}
}
});
Templates
app/templates/components/single-post.hbs
<p><button {{action "select" post}}>✓</button> {{post.title}}</p>
Templates
app/components/single-post.js
export default Ember.Component.extend({
actions: {
select(post) {
console.log(post.get('title'));
}
}
});
app/templates/components/single-post.hbs
<p>
<button {{action "select" post on="mouseUp"}}>✓</button>
{{post.title}}
</p>
Components
ember generate component my-component-name
installing component
create app/components/my-component-name.js
create app/templates/components/my-component-name.hbs
installing component-test
create tests/integration/components/my-component-name-test.js
Components
app/templates/components/blog-post.hbs
<article class="blog-post">
<h1>{{title}}</h1>
<p>{{yield}}</p>
<p>Edit title: {{input type="text" value=title}}</p>
</article>
app/templates/index.hbs
{{#each model as |post|}}
{{#blog-post title=post.title}}
{{post.body}}
{{/blog-post}}
{{/each}}
app/routes/index.js
export default Ember.Route.extend({
model() {
return this.store.findAll('post');
}
});
https://ember-twiddle.com/7ff20a68a367df12a894294d837bc391?openFiles=controllers.application.js%2Cblog-post.template.
hbs
Controllers
A controller is a routable object meant to “decorate” a model with display
logic.
Controllers
A controller is a routable object meant to “decorate” a model with display
logic.
Controllers
Ember CLI Mirage
Mirage
Ember CLI Mirage is a client side mock server to develop and prototype
applications.
Fixtures and Factories
We now have a couple of choices. We can create data using fixtures, or
generate them through a factory. It's probably a good idea to use factories.
They can easily be added to your tests.
Fixtures
Mirage
Factories
More information in...
● https://guides.emberjs.com/v2.4.0/
● http://emberjs.com/api/
● https://ember-twiddle.com/
● http://emberigniter.com/
● http://yoember.com/
Workshop 16: EmberJS Parte I
1 of 43

Recommended

Workshop 2: JavaScript Design Patterns by
Workshop 2: JavaScript Design PatternsWorkshop 2: JavaScript Design Patterns
Workshop 2: JavaScript Design PatternsVisual Engineering
1.3K views56 slides
Workshop Intro: FrontEnd General Overview by
Workshop Intro: FrontEnd General OverviewWorkshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewVisual Engineering
668 views34 slides
Workshop 9: BackboneJS y patrones MVC by
Workshop 9: BackboneJS y patrones MVCWorkshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVCVisual Engineering
601 views35 slides
Workshop 27: Isomorphic web apps with ReactJS by
Workshop 27: Isomorphic web apps with ReactJSWorkshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSVisual Engineering
944 views26 slides
AngularJS with RequireJS by
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJSJohannes Weber
8.3K views21 slides
AngularJS application architecture by
AngularJS application architectureAngularJS application architecture
AngularJS application architectureGabriele Falace
12.7K views29 slides

More Related Content

What's hot

Angularjs architecture by
Angularjs architectureAngularjs architecture
Angularjs architectureMichael He
999 views22 slides
Workshop 21: React Router by
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React RouterVisual Engineering
2.8K views12 slides
Angularjs by
AngularjsAngularjs
AngularjsVincenzo Ferrari
2.1K views17 slides
Angular js by
Angular jsAngular js
Angular jsManav Prasad
590 views30 slides
Introduction to AngularJS by
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJSJussi Pohjolainen
9.7K views95 slides
AngularJS 101 - Everything you need to know to get started by
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedStéphane Bégaudeau
55.5K views41 slides

What's hot(20)

Angularjs architecture by Michael He
Angularjs architectureAngularjs architecture
Angularjs architecture
Michael He999 views
AngularJS 101 - Everything you need to know to get started by Stéphane Bégaudeau
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau55.5K views
Building a Startup Stack with AngularJS by FITC
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
FITC32K views
AngularJS - What is it & Why is it awesome ? (with demos) by Gary Arora
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora37.3K views
Angularjs - lazy loading techniques by Nir Kaufman
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques
Nir Kaufman131.9K views
Angular Lazy Loading and Resolve (Route Resolver) by Squash Apps Pvt Ltd
Angular Lazy Loading and Resolve (Route Resolver)Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)
Squash Apps Pvt Ltd1.6K views
Advanced Tips & Tricks for using Angular JS by Simon Guest
Advanced Tips & Tricks for using Angular JSAdvanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JS
Simon Guest19.4K views
AngularJS for Java Developers by Loc Nguyen
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
Loc Nguyen4.1K views
AngularJS for designers and developers by Kai Koenig
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
Kai Koenig10.2K views
Angular JS - Introduction by Sagar Acharya
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
Sagar Acharya2.4K views

Viewers also liked

Change document display by
Change document displayChange document display
Change document displayRadosław Gref
300 views6 slides
Workshop iOS 3: Testing, protocolos y extensiones by
Workshop iOS 3: Testing, protocolos y extensionesWorkshop iOS 3: Testing, protocolos y extensiones
Workshop iOS 3: Testing, protocolos y extensionesVisual Engineering
695 views49 slides
Unlock The Value Of Your Microsoft and SAP Investments by
Unlock The Value Of Your Microsoft and SAP InvestmentsUnlock The Value Of Your Microsoft and SAP Investments
Unlock The Value Of Your Microsoft and SAP InvestmentsSAP Technology
3.6K views28 slides
CDS Unit Testing by
CDS Unit TestingCDS Unit Testing
CDS Unit TestingChrisESwanepoel
1K views7 slides
Workshop iOS 4: Closures, generics & operators by
Workshop iOS 4: Closures, generics & operatorsWorkshop iOS 4: Closures, generics & operators
Workshop iOS 4: Closures, generics & operatorsVisual Engineering
507 views7 slides
Workshop 11: Trendy web designs & prototyping by
Workshop 11: Trendy web designs & prototypingWorkshop 11: Trendy web designs & prototyping
Workshop 11: Trendy web designs & prototypingVisual Engineering
823 views68 slides

Viewers also liked(20)

Workshop iOS 3: Testing, protocolos y extensiones by Visual Engineering
Workshop iOS 3: Testing, protocolos y extensionesWorkshop iOS 3: Testing, protocolos y extensiones
Workshop iOS 3: Testing, protocolos y extensiones
Visual Engineering695 views
Unlock The Value Of Your Microsoft and SAP Investments by SAP Technology
Unlock The Value Of Your Microsoft and SAP InvestmentsUnlock The Value Of Your Microsoft and SAP Investments
Unlock The Value Of Your Microsoft and SAP Investments
SAP Technology3.6K views
Workshop iOS 4: Closures, generics & operators by Visual Engineering
Workshop iOS 4: Closures, generics & operatorsWorkshop iOS 4: Closures, generics & operators
Workshop iOS 4: Closures, generics & operators
Visual Engineering507 views
Workshop 11: Trendy web designs & prototyping by Visual Engineering
Workshop 11: Trendy web designs & prototypingWorkshop 11: Trendy web designs & prototyping
Workshop 11: Trendy web designs & prototyping
Visual Engineering823 views
Multithreading 101 by Tim Penhey
Multithreading 101Multithreading 101
Multithreading 101
Tim Penhey1.4K views
JavaScript for ABAP Programmers - 7/7 Functional Programming by Chris Whealy
JavaScript for ABAP Programmers - 7/7 Functional ProgrammingJavaScript for ABAP Programmers - 7/7 Functional Programming
JavaScript for ABAP Programmers - 7/7 Functional Programming
Chris Whealy3.1K views
Automated Testing Of Web Applications Using XML by diongillard
Automated  Testing Of  Web  Applications Using  XMLAutomated  Testing Of  Web  Applications Using  XML
Automated Testing Of Web Applications Using XML
diongillard7K views
Getting Started with OpenUI5 (San Francisco State University) by Alexander Graebe
Getting Started with OpenUI5 (San Francisco State University)Getting Started with OpenUI5 (San Francisco State University)
Getting Started with OpenUI5 (San Francisco State University)
Alexander Graebe2.9K views
Python Intro by Tim Penhey
Python IntroPython Intro
Python Intro
Tim Penhey3.4K views
SAP for Utilities 2015 FINAL HOTLIST by Jonathan Toomey
SAP for Utilities 2015 FINAL HOTLISTSAP for Utilities 2015 FINAL HOTLIST
SAP for Utilities 2015 FINAL HOTLIST
Jonathan Toomey403 views
Introduction to Design Thinking by Blackvard
Introduction to Design ThinkingIntroduction to Design Thinking
Introduction to Design Thinking
Blackvard 1.6K views
Consuming Data With HANA XS by Blackvard
Consuming Data With HANA XSConsuming Data With HANA XS
Consuming Data With HANA XS
Blackvard 1.6K views

Similar to Workshop 16: EmberJS Parte I

Phoenix for Rails Devs by
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails DevsDiacode
1K views66 slides
RoR 101: Session 2 by
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2Rory Gianni
813 views38 slides
WebNet Conference 2012 - Designing complex applications using html5 and knock... by
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
1.6K views36 slides
Introduction to ember js by
Introduction to ember jsIntroduction to ember js
Introduction to ember jsAdnan Arshad
528 views18 slides
Introduction to Ember.js by
Introduction to Ember.jsIntroduction to Ember.js
Introduction to Ember.jsVinoth Kumar
454 views16 slides
Workshop 17: EmberJS parte II by
Workshop 17: EmberJS parte IIWorkshop 17: EmberJS parte II
Workshop 17: EmberJS parte IIVisual Engineering
856 views54 slides

Similar to Workshop 16: EmberJS Parte I(20)

Phoenix for Rails Devs by Diacode
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
Diacode1K views
RoR 101: Session 2 by Rory Gianni
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
Rory Gianni813 views
WebNet Conference 2012 - Designing complex applications using html5 and knock... by Fabio Franzini
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini1.6K views
Introduction to ember js by Adnan Arshad
Introduction to ember jsIntroduction to ember js
Introduction to ember js
Adnan Arshad528 views
Introduction to Ember.js by Vinoth Kumar
Introduction to Ember.jsIntroduction to Ember.js
Introduction to Ember.js
Vinoth Kumar454 views
The road to Ember.js 2.0 by Codemotion
The road to Ember.js 2.0The road to Ember.js 2.0
The road to Ember.js 2.0
Codemotion838 views
GHC by AidIQ
GHCGHC
GHC
AidIQ578 views
Create an application with ember by Chandra Sekar
Create an application with ember Create an application with ember
Create an application with ember
Chandra Sekar288 views
JavaScript Modules Done Right by Mariusz Nowak
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
Mariusz Nowak5.4K views
Building Single Page Application (SPA) with Symfony2 and AngularJS by Antonio Peric-Mazar
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
Reactive application using meteor by Sapna Upreti
Reactive application using meteorReactive application using meteor
Reactive application using meteor
Sapna Upreti278 views
Intro to EmberJS by Billy Onjea
Intro to EmberJSIntro to EmberJS
Intro to EmberJS
Billy Onjea157 views
Build Web Apps using Node.js by davidchubbs
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.js
davidchubbs675 views
SproutCore and the Future of Web Apps by Mike Subelsky
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
Mike Subelsky708 views
Ruby on Rails - Introduction by Vagmi Mudumbai
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
Vagmi Mudumbai859 views

More from Visual Engineering

Workshop iOS 2: Swift - Structures by
Workshop iOS 2: Swift - StructuresWorkshop iOS 2: Swift - Structures
Workshop iOS 2: Swift - StructuresVisual Engineering
553 views25 slides
Workshop 26: React Native - The Native Side by
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideVisual Engineering
2.8K views54 slides
Workshop 23: ReactJS, React & Redux testing by
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingVisual Engineering
1.8K views23 slides
Workshop 22: ReactJS Redux Advanced by
Workshop 22: ReactJS Redux AdvancedWorkshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux AdvancedVisual Engineering
1.3K views29 slides
Workshop 22: React-Redux Middleware by
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareVisual Engineering
2.3K views29 slides
Workshop 20: ReactJS Part II Flux Pattern & Redux by
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxVisual Engineering
1.2K views19 slides

More from Visual Engineering(18)

Workshop 26: React Native - The Native Side by Visual Engineering
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
Visual Engineering2.8K views
Workshop 23: ReactJS, React & Redux testing by Visual Engineering
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
Visual Engineering1.8K views
Workshop 20: ReactJS Part II Flux Pattern & Redux by Visual Engineering
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
Visual Engineering1.2K views
Workshop 18: CSS Animations & cool effects by Visual Engineering
Workshop 18: CSS Animations & cool effectsWorkshop 18: CSS Animations & cool effects
Workshop 18: CSS Animations & cool effects
Visual Engineering1.2K views
Workshop 4: NodeJS. Express Framework & MongoDB. by Visual Engineering
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering1.6K views

Recently uploaded

predicting-m3-devopsconMunich-2023.pptx by
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptxTier1 app
7 views24 slides
Programming Field by
Programming FieldProgramming Field
Programming Fieldthehardtechnology
6 views9 slides
JioEngage_Presentation.pptx by
JioEngage_Presentation.pptxJioEngage_Presentation.pptx
JioEngage_Presentation.pptxadmin125455
6 views4 slides
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation by
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook AutomationDRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook AutomationHCLSoftware
6 views8 slides
How Workforce Management Software Empowers SMEs | TraQSuite by
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteTraQSuite
5 views3 slides
Fleet Management Software in India by
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India Fleetable
12 views1 slide

Recently uploaded(20)

predicting-m3-devopsconMunich-2023.pptx by Tier1 app
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptx
Tier1 app7 views
JioEngage_Presentation.pptx by admin125455
JioEngage_Presentation.pptxJioEngage_Presentation.pptx
JioEngage_Presentation.pptx
admin1254556 views
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation by HCLSoftware
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook AutomationDRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation
HCLSoftware6 views
How Workforce Management Software Empowers SMEs | TraQSuite by TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuite
TraQSuite5 views
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable12 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok15 views
Bootstrapping vs Venture Capital.pptx by Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic14 views
FIMA 2023 Neo4j & FS - Entity Resolution.pptx by Neo4j
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptx
Neo4j17 views
AI and Ml presentation .pptx by FayazAli87
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptx
FayazAli8713 views
Quality Engineer: A Day in the Life by John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino7 views
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... by TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin96 views
ADDO_2022_CICID_Tom_Halpin.pdf by TomHalpin9
ADDO_2022_CICID_Tom_Halpin.pdfADDO_2022_CICID_Tom_Halpin.pdf
ADDO_2022_CICID_Tom_Halpin.pdf
TomHalpin95 views
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... by NimaTorabi2
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
NimaTorabi215 views
Top-5-production-devconMunich-2023.pptx by Tier1 app
Top-5-production-devconMunich-2023.pptxTop-5-production-devconMunich-2023.pptx
Top-5-production-devconMunich-2023.pptx
Tier1 app8 views
Electronic AWB - Electronic Air Waybill by Freightoscope
Electronic AWB - Electronic Air Waybill Electronic AWB - Electronic Air Waybill
Electronic AWB - Electronic Air Waybill
Freightoscope 5 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy14 views

Workshop 16: EmberJS Parte I

  • 1. Raúl Delgado & Andrés Lamilla Front End Workshops EmberJS General Overview rdelgado@visual-engin.com alamilla@visual-engin.com
  • 2. A framework for creating ambitious web applications.
  • 3. ● Focus on ambitious web applications: applications that look and act like desktop applications, but happen to be delivered via web technologies ● More productive out of the box: provide a complete development stack to make the developer productive immediately. (Ember CLI, application structure, thousands addons). ● Stability without stagnation: backward compatibility is important and can be maintained while still innovating and evolving the framework. ● Future web standards foresight: pioneer of many standards around Javascript and the web. (promises, web components and ES6 syntax) Philosophy
  • 4. ● Routes: the state of an application is represented by a URL ● Models: data associated with the current state of the application ● Templates: HTMLBars templating language. (Handlebars variation) ● Components: custom HTML tag ● Services: singleton objects to hold long-lived data such as user sessions Five essential Concepts
  • 6. ● In December 2011, the SproutCore 2.0 framework was renamed to Ember.js ● The framework was created by Yehuda Katz, a member of the jQuery, Ruby on Rails and SproutCore core teams ● Ember follows a six-week release cycle. Every six weeks a new release is made available, and at the same time a beta for the next release is also published ● Ember follows the semantic versioning convention. This means that breaking changes are only introduced at major version numbers such as 1.0, 2.0 etc. ● Ember 2.0 was released August 13, 2015. Introduction of the Glimmer rendering engine ● It follows the Convention over configuration design paradigm ● Stable release 2.4.3 / March 17, 2016 Facts
  • 8. ● Strong conventional project structure ● Powerful addon system for extension ● Uses babel, which turns ES2015 module syntax into AMD (RequireJS-esq) modules. ● Use QUnit and Ember QUnit by default. But, you are free to use other options such as Mocha and Ember Mocha. ● Use Bower, for front-end dependencies and npm, for managing internal dependencies ● Is configurable via a file named .ember-cli Ember cli
  • 9. Has support for: ● Handlebars ● HTMLBars ● Emblem ● LESS ● Sass ● Compass ● Stylus ● CoffeeScript ● EmberScript ● Minified JS & CSS Ember cli
  • 10. Commands: ● ember ● ember new <app-name> ● ember init ● ember build ● ember server ● ember generate <generator-name> <options> ● ember help generate ● ember destroy <generator-name> <options> ● ember test ● ember install <addon-name> Ember cli
  • 11. npm install -g ember-cli@2.4 ember new ember-quickstart cd ember-quickstart ember serve Livereload server on http://localhost:49152 Serving on http://localhost:4200/ ember generate route scientists installing route create app/routes/scientists.js create app/templates/scientists.hbs updating router add route scientists installing route-test create tests/unit/routes/scientists-test.js ember build --env production Ember cli
  • 12. ember install ember-cli-sass ember install ember-cli-bootstrap-sassy mv app/styles/app.css app/styles/app.scss echo '@import "bootstrap";' > app/styles/app.scss Ember cli
  • 14. Ember implements its own object system. The base object is Ember.Object. All of the other objects in Ember extend Ember.Object. Ember.Object can observe properties change. This simple architectural decision is responsible for much of the consistency across Ember. Every Ember object can observe the properties of other objects, bind their properties to the properties of other objects, specify and update computed properties, and much more. This gives enormous power and flexibility ! Ember.object
  • 16. Defining new Ember Class: Ember.object Properties: person1 = Person.extend({ firstName: “John”, lastName: “McClaine”, fullName(): { let fullName = this.firstName + ‘ ’ + this.lastName; alert(`my name is ${fullName} !`) } }) person1.get(‘firstName’) //John person1.get(‘lastName’) //McClane person1.fullName() //my name is John Mclane ! Person = Ember.Object.extend() user = Person.create()
  • 17. Observers: Ember.object Person = Ember.Object.extend({ firstName: null, lastName: null, fullName: Ember.computed( 'firstName', 'lastName', function() { return `${this.get('firstName')} ${this.get('lastName')}`; }), fullNameChanged: Ember.observer( 'fullName', () => { // deal with the change console.log(`fullName changed to: ${this.get('fullName')}`); }) }) var person = Person.create({ firstName : Harry, lastName : ‘Stamper’ }) person.get(‘fullName’) // Harry Stamper person.set(‘firstName’, “Grace”) // fullName changet to: Grace Stamper
  • 19. The models are objects that represent the underlying data that the application presents the user. Different applications have very different models, depending on what are the problems they are trying to solve. You can create a model with the command: This will generate: Models $ ember generate model person
  • 20. Models Defining attributes: To define attributes to our model, we have four methods: - Attr - hasMany - belonsTo - normalizeModelName attr:
  • 21. Models Relationship methods: hasMany & belongsTo: One-to-one: One-to-many: Many-to-many:
  • 23. Ember is URL-driven so it always starts in the URL. In the example, our router has the following definition: Routing An instance of the Route invoke the model() method where we turn the model. Here it looks like a dummy object is returned: Once model() has been returned, the renderComponent() method call ItemDisplayComponent model.
  • 24. Not only push data paths. They can also receive actions. Actions are sent from components or other routes, so that the logic transitions involving URL or another route-level issue. Routing
  • 25. Routing What’s going on here? 1. The Router parses the /items/2 URL and dispatches control to a matching route: ItemRoute with a parameter item_id=2 2. ItemRoute invokes its model() hook, in which our app returns a model (Item with id=2) fetched via a service 3. renderComponent() is then run to render the component ItemDisplayComponent, passing it the resolved model Item 4. ItemDisplayComponent is responsible for the user interface: rendering/updating the DOM, and handling browser events
  • 26. The application route is entered when your app first boots up. Like other routes, it will load a template with the same name (application in this case) by default. You should put your header, footer, and any other decorative content here. All other routes will render their templates into the application.hbs template's {{outlet}}. This route is part of every application, so you don't need to specify it in your app/router.js. Routing The application route: Index Routes: At every level of nesting (including the top level), Ember automatically provides a route for the / path named index.
  • 28. app/helpers/sum.js export function sum(params) { return params.reduce((a, b) => { return a + b; }); }; export default Ember.Helper.helper(sum); Templates <p>Total: {{sum 1 2 3}}</p> {{sum (multiply 2 4) 2}}
  • 29. <div> {{if isFast "I am fast" "I am slow"}} </div> Templates <div> {{if isFast (if isFueled "zoooom")}} </div> {{#if isAtWork}} Ship that code! {{else if isReading}} You can finish War and Peace eventually... {{/if}}
  • 30. {{#each people as |person|}} Hello, {{person.name}}! {{else}} Sorry, nobody is here. {{/each}} Templates <ul> {{#each people as |person index|}} <li>Hello, {{person.name}}! You're number {{index}} in line</li> {{/each}} </ul>
  • 31. /app/components/store-categories.js export default Ember.Component.extend({ willRender() { this.set('categories', { 'Bourbons': ['Bulleit', 'Four Roses', 'Woodford Reserve'], 'Ryes': ['WhistlePig', 'High West'] }); } }); Templates /app/templates/components/store-categories.hbs <ul> {{#each-in categories as |category products|}} <li>{{category}} <ol> {{#each products as |product|}} <li>{{product}}</li> {{/each}} </ol> </li> {{/each-in}} </ul> <ul> <li>Bourbons <ol> <li>Bulleit</li> <li>Four Roses</li> <li>Woodford Reserve</li> </ol> </li> <li>Ryes <ol> <li>WhistlePig</li> <li>High West</li> </ol> </li> </ul>
  • 32. /app/components/store-categories.js export default Ember.Component.extend({ willRender() { this.set('categories', { 'Bourbons': ['Bulleit', 'Four Roses', 'Woodford Reserve'], 'Ryes': ['WhistlePig', 'High West'] }); }, actions: { addCategory(category) { let categories = this.get('categories'); categories[category] = [ ]; // A manual re-render causes the DOM to be updated this.rerender(); } } }); Templates
  • 33. app/templates/components/single-post.hbs <p><button {{action "select" post}}>✓</button> {{post.title}}</p> Templates app/components/single-post.js export default Ember.Component.extend({ actions: { select(post) { console.log(post.get('title')); } } }); app/templates/components/single-post.hbs <p> <button {{action "select" post on="mouseUp"}}>✓</button> {{post.title}} </p>
  • 35. ember generate component my-component-name installing component create app/components/my-component-name.js create app/templates/components/my-component-name.hbs installing component-test create tests/integration/components/my-component-name-test.js Components app/templates/components/blog-post.hbs <article class="blog-post"> <h1>{{title}}</h1> <p>{{yield}}</p> <p>Edit title: {{input type="text" value=title}}</p> </article> app/templates/index.hbs {{#each model as |post|}} {{#blog-post title=post.title}} {{post.body}} {{/blog-post}} {{/each}} app/routes/index.js export default Ember.Route.extend({ model() { return this.store.findAll('post'); } }); https://ember-twiddle.com/7ff20a68a367df12a894294d837bc391?openFiles=controllers.application.js%2Cblog-post.template. hbs
  • 37. A controller is a routable object meant to “decorate” a model with display logic. Controllers
  • 38. A controller is a routable object meant to “decorate” a model with display logic. Controllers
  • 40. Mirage Ember CLI Mirage is a client side mock server to develop and prototype applications. Fixtures and Factories We now have a couple of choices. We can create data using fixtures, or generate them through a factory. It's probably a good idea to use factories. They can easily be added to your tests.
  • 42. More information in... ● https://guides.emberjs.com/v2.4.0/ ● http://emberjs.com/api/ ● https://ember-twiddle.com/ ● http://emberigniter.com/ ● http://yoember.com/