Weitere ähnliche Inhalte Ähnlich wie Emberjs building-ambitious-web-applications Ähnlich wie Emberjs building-ambitious-web-applications (20) Mehr von ColdFusionConference Mehr von ColdFusionConference (20) Kürzlich hochgeladen (20) Emberjs building-ambitious-web-applications2. About Me
• Senior UI Engineer at Netflix
• Friend of Open Source
• @bittersweetryan
19. Application & App.Router
App.Router.map(function() {
!
this.resource( 'sessions', { path : 'sessions' }, function(){
this.route( 'add' );
} );
this.route( 'session', { path : 'session/:id'} );
!
this.resource( 'speakers', { path : 'speakers' }, function(){
this.route( 'speaker', { path : '/:name' } );
});
});
A resource can have nested routeshttp://<server>/#/sessions
http://<server>/#/sessions/add
http://<server>/#/session/1
http://<server>/#/speakers
http://<server>/#/speakers/Ryan%20Anklam
22. Templates
<script type="text/x-handlebars">
<header>
<h1> Welcome to cf.Objective (2014)</h1>
</header>
<nav>
<ul>
<li class="nav-item">{{#link-to 'index'}}Home{{/link-to}}</li>
<li class="nav-item">{{#link-to 'sessions'}}Sessions{{/link-to}}</li>
<li class="nav-item">{{#link-to 'speakers'}}Speakers{{/link-to}}</li>
</ul>
</nav>
<div class="content">
{{outlet}}
</div>
</script>
http://<server>/
http://<server>/#/sessions
http://<server>/#/speakers
Routes will output here
33. Controllers
App.SessionController = Ember.ObjectController.extend({
actions : {
going : function( session ){
session.toggleProperty( 'going' );
!
}
},
goingClass : function(){
return (this.get( 'going' ))? 'attending' : '';
}.property( 'going' )
});
this.route( 'session', { path : 'session/:id'} );
<button {{action 'going' this}} class=“button">
<h2 {{bind-attr class=goingClass}}>
37. Ember Data
• Swappable Adapters
• Relationships
• Fully embraces promises
• Data caching
• Fixtures speed up development
40. Store
App.Session = DS.Model.extend({
track : DS.attr( 'string' ),
name : DS.attr( 'string' ),
description: DS.attr( 'string' ),
going: DS.attr( 'boolean', {defaultValue : false} ),
speaker : DS.belongsTo('speaker')
});
this.route( 'session', { path : 'session/:id'} );
41. Store
App.Speaker = DS.Model.extend({
firstName : DS.attr( 'string' ),
lastName : DS.attr('string'),
fullName : function(){
return
this.get( 'firstName' ) + ' ' + this.get( 'lastName' );
}.property( 'firstName', 'lastName' ),
bio : DS.attr( 'string' ),
sessions: DS.hasMany('session', { async : true } )
});