Upgrade to Pro — share decks privately, control downloads, hide ads and more …

EmberJS Intro

EmberJS Intro

Avatar for catalin.ion

catalin.ion

March 06, 2015

Other Decks in Programming

Transcript

  1. WHAT IS EMBER Client-side JavaScript application framework based on the

    MVC pattern. • Router • MVC • Components • Convention over configuration
  2. ROUTER • Translates a URL into a series of nested

    templates • Manages application state • Keeps the URL up-to-date ROUTE • tells the template which model it should display
  3. // app/router.js var Router = Ember.Router.extend({}); Router.map(function() { this.route('articles'); });

    // app/routes/articles.js export default Ember.Route.extend({ model: function () { return this.store.find('article'); } });
  4. MODEL • defines the properties and behavior of the data

    • stores persistent state STORE • central repository of records in your application • created for you automatically • shared among all of the objects
  5. // app/models/article.js import DS from 'ember-data'; export default DS.Model.extend({ title:

    DS.attr('string'), author: DS.attr('string'), publishedAt: DS.attr('date'), published: DS.attr('boolean') });
  6. CONTROLLER • stores application state • is more of a

    ViewModel or Presenter • used to decorate models with display logic ObjectController • wraps a single model ArrayController • wraps an array of models
  7. TEMPLATES • Describes the user interface • Backed by a

    model • Used to be written in Handlebars • As of 1.10 HTMLBars is used CAN CONTAIN • HTML • Expressions {{title}} • Outlets - placeholders for other templates • Components
  8. COMPONENTS • custom HTML tag • behavior implemented using JavaScript

    • interface described using HTMLBars • you can pass data to components • wrap content in a component • components can send action to your app
  9. // app/components/collapsible.js export default Ember.Component.extend({ tagName: 'collapsible', actions: { toggle:

    function () { this.toggleProperty('isExpanded'); } } }); {{! app/templates/components/collpsible-widget.hbs }} <div> <a {{action "toggle"}} > {{title}}</a> </div> {{#if isExpanded}} {{yield}} {{/if}}
  10. EMBER-CLI • Command line utility • Scaffolding a new app

    • Generators • Assets Compilation • ES6 Modules • Testings • Preconfigured to use QUnit • Addons