EmberJS Essentials

17

description

EmberJS Power Point presentation

Transcript of EmberJS Essentials

Page 1: EmberJS Essentials
Page 2: EmberJS Essentials

“A Framework for Creating Ambitious Web Applications”

- Less code with Handlebars

- Updates automatically

- Incorporates common idioms

- Build for productivity

- MV* architecture

What is Ember?

Page 3: EmberJS Essentials

Getting started

www.emberjs.com

Page 4: EmberJS Essentials

Obtaining and dependencies

- jQuery

- Handlebars

- Ember.js

- Ember Data<!-- ... additional lines truncated for brevity ... --> <script src="js/libs/jquery-1.11.1.min.js"></script> <script src="js/libs/handlebars-v1.3.0.js"></script> <script src="js/libs/ember.js"></script> <script src="js/libs/ember-data.js"></script></body><!-- ... additional lines truncated for brevity ... -->

Page 5: EmberJS Essentials

Core Concepts

- Templates

- Router

- Components

- Models

- Route

- Controllers

Page 6: EmberJS Essentials

Handlebars

www.handlebarsjs.com

Build semantic templates effectively

<div class="entry"> <h1>{{title}}</h1> <div class="body"> {{body}} </div></div>

Page 7: EmberJS Essentials

Ember Handlebars

Conditions{{#if person}} Welcome back, <b>{{person.firstName}} {{person.lastName}}</b>!{{/if}}

List of items<ul> {{#each person in people}} <li>Hello, {{person.name}}!</li> {{/each}}</ul>

Attributes<div id="logo"> <img {{bind-attr src=logoUrl}} alt="Logo"></div>

Page 8: EmberJS Essentials

Ember Handlebars

Links<ul>{{#each photo in photos}} <li>{{#link-to 'photos.edit' photo}}{{photo.title}}{{/link-to}}</li>{{/each}}</ul>

Input{{input type="text" value=firstName disabled=entryNotAllowed size="50"}}

Page 9: EmberJS Essentials

Ember Handlebars

Actions{{#if isExpanded}} <div class='body'>{{body}}</div> <button {{action 'contract'}}>Contract</button>{{else}} <button {{action 'expand'}}>Show More...</button>{{/if}}

App.PostController = Ember.ObjectController.extend({ // initial value isExpanded: false,

actions: { expand: function() { this.set('isExpanded', true); },

contract: function() { this.set('isExpanded', false); } }});

Page 10: EmberJS Essentials

Ember Handlebars

Development helpers{{log}}{{debugger}}

Rendering{{partial}}{{view}}{{render}}

Page 11: EmberJS Essentials

Routing

App.Router.map(function() { this.route("about", { path: "/about" }); this.route("favorites", { path: "/favs" });});

App.Router.map(function() { this.resource('posts', { path: '/posts' }, function() { this.route('new'); });});

Heads up! You get a few routes for free: the ApplicationRoute and the IndexRoute (corresponding to the / path).

Page 12: EmberJS Essentials

Components

<script type="text/x-handlebars" id="components/blog-post"> <h1>Blog Post</h1> <p>Lorem ipsum dolor sit amet.</p></script>

<h1>My Blog</h1>{{#each post in model}} {{blog-post}}{{/each}}

Page 13: EmberJS Essentials

Controllers

App.ApplicationController = Ember.Controller.extend({ // the initial value of the `search` property search: '',

actions: { query: function() { // the current value of the text field var query = this.get('search'); this.transitionToRoute('search', { query: query }); } }});

Page 14: EmberJS Essentials

Views

<script type="text/x-handlebars" data-template-name="say-hello"> Hello, <b>{{view.name}}</b></script>

var view = Ember.View.create({ templateName: 'say-hello', name: "Bob"});

view.appendTo('#container');

- When you need sophisticated handling of user events

- When you want to create a re-usable component

Page 15: EmberJS Essentials

Views

{{#view "clickable"}}This is a clickable area!{{/view}}

App.ClickableView = Ember.View.extend({ click: function(evt) { alert("ClickableView was clicked!"); }});

Example of Handling events

Page 16: EmberJS Essentials

Testing

test('root lists first page of posts', function(){ visit('/posts'); andThen(function() { equal(find('ul.posts li').length, 3, 'The first page should have 3 posts'); });});

- Integration Tests- Unit Tests

QUnit - example of testing framework

Page 17: EmberJS Essentials

Application