SlideShare una empresa de Scribd logo
1 de 43
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
Kai Koenig
 

La actualidad más candente (20)

Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architecture
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
Angularjs
AngularjsAngularjs
Angularjs
 
Angular js
Angular jsAngular js
Angular js
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
AngularJS 101 - Everything you need to know to get started
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
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
AngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXAngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UX
 
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)
AngularJS - What is it & Why is it awesome ? (with demos)
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)
 
Advanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JSAdvanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JS
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
AngularJS introduction
AngularJS introductionAngularJS introduction
AngularJS introduction
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
AngularJS Basic Training
AngularJS Basic TrainingAngularJS Basic Training
AngularJS Basic Training
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 

Destacado

SAP for Utilities 2015 FINAL HOTLIST
SAP for Utilities 2015 FINAL HOTLISTSAP for Utilities 2015 FINAL HOTLIST
SAP for Utilities 2015 FINAL HOTLIST
Jonathan Toomey
 

Destacado (20)

Change document display
Change document displayChange document display
Change document display
 
Workshop iOS 3: Testing, protocolos y extensiones
Workshop iOS 3: Testing, protocolos y extensionesWorkshop iOS 3: Testing, protocolos y extensiones
Workshop iOS 3: Testing, protocolos y extensiones
 
Unlock The Value Of Your Microsoft and SAP Investments
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
 
CDS Unit Testing
CDS Unit TestingCDS Unit Testing
CDS Unit Testing
 
Workshop iOS 4: Closures, generics & operators
Workshop iOS 4: Closures, generics & operatorsWorkshop iOS 4: Closures, generics & operators
Workshop iOS 4: Closures, generics & operators
 
Workshop 11: Trendy web designs & prototyping
Workshop 11: Trendy web designs & prototypingWorkshop 11: Trendy web designs & prototyping
Workshop 11: Trendy web designs & prototyping
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101
 
Hana sql
Hana sql Hana sql
Hana sql
 
JavaScript for ABAP Programmers - 7/7 Functional Programming
JavaScript for ABAP Programmers - 7/7 Functional ProgrammingJavaScript for ABAP Programmers - 7/7 Functional Programming
JavaScript for ABAP Programmers - 7/7 Functional Programming
 
Workshop 24: React Native Introduction
Workshop 24: React Native IntroductionWorkshop 24: React Native Introduction
Workshop 24: React Native Introduction
 
Automated Testing Of Web Applications Using XML
Automated  Testing Of  Web  Applications Using  XMLAutomated  Testing Of  Web  Applications Using  XML
Automated Testing Of Web Applications Using XML
 
Getting Started with OpenUI5 (San Francisco State University)
Getting Started with OpenUI5 (San Francisco State University)Getting Started with OpenUI5 (San Francisco State University)
Getting Started with OpenUI5 (San Francisco State University)
 
Python Intro
Python IntroPython Intro
Python Intro
 
SAP for Utilities 2015 FINAL HOTLIST
SAP for Utilities 2015 FINAL HOTLISTSAP for Utilities 2015 FINAL HOTLIST
SAP for Utilities 2015 FINAL HOTLIST
 
Introduction to Design Thinking
Introduction to Design ThinkingIntroduction to Design Thinking
Introduction to Design Thinking
 
Workhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de SwiftWorkhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de Swift
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
Consuming Data With HANA XS
Consuming Data With HANA XSConsuming Data With HANA XS
Consuming Data With HANA XS
 
OpenUI5
OpenUI5OpenUI5
OpenUI5
 
Workshop 25: React Native - Components
Workshop 25: React Native - ComponentsWorkshop 25: React Native - Components
Workshop 25: React Native - Components
 

Similar a Workshop 16: EmberJS Parte I

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...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 

Similar a Workshop 16: EmberJS Parte I (20)

Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
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...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Introduction to ember js
Introduction to ember jsIntroduction to ember js
Introduction to ember js
 
Introduction to Ember.js
Introduction to Ember.jsIntroduction to Ember.js
Introduction to Ember.js
 
Workshop 17: EmberJS parte II
Workshop 17: EmberJS parte IIWorkshop 17: EmberJS parte II
Workshop 17: EmberJS parte II
 
The road to Ember.js 2.0
The road to Ember.js 2.0The road to Ember.js 2.0
The road to Ember.js 2.0
 
Full slidescr16
Full slidescr16Full slidescr16
Full slidescr16
 
GHC
GHCGHC
GHC
 
Create an application with ember
Create an application with ember Create an application with ember
Create an application with ember
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
 
IOC + Javascript
IOC + JavascriptIOC + Javascript
IOC + Javascript
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
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
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
Intro to EmberJS
Intro to EmberJSIntro to EmberJS
Intro to EmberJS
 
RequireJS
RequireJSRequireJS
RequireJS
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.js
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 

Más de Visual Engineering

Más de Visual Engineering (18)

Workshop iOS 2: Swift - Structures
Workshop iOS 2: Swift - StructuresWorkshop iOS 2: Swift - Structures
Workshop iOS 2: Swift - Structures
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Workshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux AdvancedWorkshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux Advanced
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS Introduction
 
Workshop 18: CSS Animations & cool effects
Workshop 18: CSS Animations & cool effectsWorkshop 18: CSS Animations & cool effects
Workshop 18: CSS Animations & cool effects
 
Workshop 15: Ionic framework
Workshop 15: Ionic frameworkWorkshop 15: Ionic framework
Workshop 15: Ionic framework
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
 
Workshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJSWorkshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJS
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Workshop 7: Single Page Applications
Workshop 7: Single Page ApplicationsWorkshop 7: Single Page Applications
Workshop 7: Single Page Applications
 
Workshop 6: Designer tools
Workshop 6: Designer toolsWorkshop 6: Designer tools
Workshop 6: Designer tools
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
 
Workshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsWorkshop 3: JavaScript build tools
Workshop 3: JavaScript build tools
 

Último

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 

Último (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 

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/