On Github ryandjurovich / ember-intro-slides
Ember.js
Ember Data
Ember App Kit
JavaScript
MDN JavaScript Guide Task Runner Grunt.jsTemplating
Handlebars.jsData Storage
JSONOverview
Terminology
Router
Route
Model
Controller
Template
Views
Components
Ember.js is a JavaScript web application framework based on the model-view-controller (MVC) pattern.
It includes a rich object model, two-way data binding, computed properties, auto-updating templates, and a router for managing application state.
Defines available Routes.
"This URL loads this Route"
App.Router.map(function() { // AboutRoute this.route("about", { path: "/about" }); // PostsRoute this.resource("posts", function() { // PostsNewRoute this.route("new"); // PostsEditRoute this.route("edit", { path: ":id"}); }); });
Finds the Model and sets up the Controller
Handles actions
"Find Post with URL id parameter"
"Handles save action"
App.PostsRoute = Ember.Route.extend({ model: function(params) { return this.store.find('post', params.id); } });
Represents a Thing.
Where plural is used for Routes, Controllers, etc.
we use the singular for a Model name.
e.g. "Post"
App.Post = DS.Model.extend({ title: DS.attr('string'), body: DS.attr('string'), author: DS.attr('string'), published: DS.attr('boolean'), date: DS.attr('date') });
Maps Model to Template, Controls App/Template State.
E.g. How many published posts listed?
App.PostsController = Ember.ArrayController.extend({ numPublished: function() { var publishedPosts = this.filter(function(post) { return post.get('published') > 0; }); return publishedPosts.get('length'); }.property('@each.published') });
Two main base controllers: Array and Object.
Controls layout and display of Model & Controller data
(HTML/Handlebars)
<h1>Posts</h1> <ul> {{#each}} <li>{{title}} by {{author}}</li> {{/each}} </ul> Total Published: {{numPublished}}v>
Create re-useable components
Components
Views
Ember tries to find Routes, Controllers, Views and Templates based on certain naming conventions. e.g. "posts" route: PostsRoute, PostsController, etc.
Otherwise Ember will instantiate its default classes. (e.g. ArrayController for RecordArray model).
Ember Extension (Chrome/Firefox/Opera) can help you identify if your classes or Embers defaults are being used.
Overview
Store
Models
Records
Adapter
Serializer
JSON API
Ember Data is a library that maps your persistence
layer (e.g. JSON API) to your Ember models,
and handles retrieving and persisting records.
Let's you interact with your storage backend
var post = store.find('post', 123);
These are your classes which extend DS.Model
Instances of the Model that hold the actual record data
Translates messages to and from your backend
e.g. DS.RESTAdapter (default)
Converts models to and from API format.
e.g. DS.JSONSerializer
Can be configured to suit your API spec.
Specification that defines the conventions
Ember Data expects from your API
Some great tools already implementing the spec.
e.g. fortune.js
Overview
Grunt
Bower
ES6 Modules
Resolver
Future
CLI
Ember App Kit helps you get a new Ember app up and running more easily.
To get started, just download the latest ZIP from the EAK repo or git clone and remove the .git directory.
You get a sensible project/directory structure, with all the tooling required for a new Ember app.
Grunt is a JavaScript task runner.
EAK Grunt configuration includes options for:
EAK uses Bower for managing packages
and dependencies.
Need a 3rd party library?
One line in bower.json and 'bower install'
# cat bower.json { "name": "my-app", "dependencies": { "handlebars": "~1.1.2", ... } } # bower install
Write your code now so it's compatible with the ECMAScript 6 module spec.
The es6-module-transpiler will transpile it to Require.js or Common.js format, so it works in todays web browsers.
Many Ember projects are currently being updated to support ES6 modules, or do already (e.g. Ember Data).
EAK includes the ember-jj-abrams-resolver which extends the standard Ember resolver to support things such as ES6 modules.
Default Resolver
Posts route would load App.PostsRoute
EAK Revolver
Posts route would load the "appkit/routes/posts" module
"The goal is to eventually replace EAK with ember-cli, a faster, more user-friendly command line tool which is currently under development."
CLI will:
Ember CLI is still Alpha.
But why wait for the future?!
npm install -g ember-cli mkdir my-cool-app cd my-cool-app ember init ember server
Report bugs on Ember CLI GitHub!
Questions?
Ryan Djurovich