Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 39 ยท Getting Started

Introduction to Ember.js

Learn what Ember.js is, how convention over configuration speeds up big web apps, how it compares with other frameworks, and how its main pieces fit together.

Ember.js is a JavaScript framework for building ambitious web applications: dashboards, admin tools, editors, and other apps that people use for hours and that teams maintain for years. It first appeared in 2011 and has kept a very stable promise ever since: you can upgrade from one version to the next without rewriting your app.

Ember is opinionated. Instead of asking you to pick a router, a state library, a build tool and a folder layout, it ships with all of these already chosen and already working together. That is the main reason to use it, and also the main thing to understand before you start.

What you get in the box

A new Ember app includes:

  • a router that maps URLs to screens, including nested screens;
  • a templating language based on Handlebars, with components, helpers and modifiers;
  • a component model (Glimmer components) with tracked state for reactivity;
  • services for shared singletons such as a session or a shopping cart;
  • Ember Data, a library for fetching, caching and saving records from an API;
  • a command line tool, ember-cli, that generates code, runs a dev server, builds for production and runs tests;
  • a testing setup with unit, rendering and application tests built in.

You will meet each of these in this track. This chapter gives you the map.

Convention over configuration

In many libraries you decide where a file goes and then tell the framework about it. In Ember the location and name of a file is the configuration. If you create app/routes/posts.js, Ember uses it for the posts route. If you create app/services/session.js, you can inject session anywhere. This is handled by the resolver, which turns a name like route:posts into a file path.

The result is that an Ember project looks almost the same from one company to the next. A developer joining your team already knows where to look.

When you are unsure where something goes, run ember generate (you will see it in the next lessons). The generator puts the file in the one correct place and writes a test for it.

The stand-in below mimics the idea. It is not Ember's real resolver, only a few lines that show how a name can map to a path. Press Run and try changing the lookups.

JS A tiny resolver: names to file paths

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The big picture

An Ember app is a tree of routes and components. The URL decides which route is active. The route loads data (the model) and gives it to a template. The template is built from components. Components show data and send actions back up when the user does something.

flowchart LR
  URL["URL /posts/42"] --> Router
  Router --> Route["Route (loads model)"]
  Route --> Template["Template"]
  Template --> Components["Components"]
  Components -- "actions up" --> Route
  Route -- "data down" --> Template
  Route <--> Store["Ember Data store"]
  Store <--> API["Your API"]

The URL drives everything: data flows down to the page, and user actions flow back up.

Ember follows the rule data down, actions up (often written DDAU). A parent passes values to a child as arguments. The child never changes those values directly; it calls a function the parent gave it. This keeps the flow of information easy to follow even in very large apps.

JS Data down, actions up

Press Run (or Ctrl + Enter) to see the console output here.

No output.

In real Ember the re-rendering part is done for you by tracked state, which the Core Concepts lesson previews and the Tracked State chapter of this track covers in depth.

Ember compared with other tools

Frameworks make different trade-offs. This is a fair summary, not a ranking:

Ember Typical "library plus add-ons" setup
Router, data layer, build, tests Included and integrated You choose and glue them
Folder layout Fixed by convention Decided by each team
Upgrades Stability promise, deprecation warnings with guides Varies per package
Learning curve Steeper at first, flatter later Gentle at first, grows with choices
Best for Large, long-lived apps, many developers Small apps, prototypes, highly custom needs

If you already know Vue or React, many ideas will feel familiar: components, arguments (called props elsewhere), and reactive state. What is different is how much Ember decides for you.

Octane and modern Ember

In 2019 Ember released Octane, an edition that modernized the programming model. It is the style used in this whole track:

  • Glimmer components written as native JavaScript classes;
  • @tracked properties instead of set() calls and computed properties;
  • the {{on}} modifier and @action for events;
  • named arguments written with @ (like @title) and the component's own properties with this.

Newer versions go further with template tag components (.gjs and .gts files, where a <template> tag sits inside the JavaScript file), which is the format we use for new code. Older tutorials may show .hbs templates next to .js files or classic Ember.Component.extend; those still work, but you should write Octane style.

A first look at real code

Here is a small component in the modern format. You do not need to understand every line yet; the following lessons explain each piece. This code is read-only on this site, because the Ember build system cannot run in your browser.

JavaScript
// app/components/greeting.gjs
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { on } from '@ember/modifier';

export default class Greeting extends Component {
  @tracked excited = false;

  toggle = () => {
    this.excited = !this.excited;
  };

  <template>
    <p>Hello, {{@name}}{{if this.excited "!" "."}}</p>
    <button type="button" {{on "click" this.toggle}}>Toggle</button>
  </template>
}

Notice @name, an argument passed in by the parent, and this.excited, state owned by the component. Changing a tracked property re-renders exactly the parts of the template that use it.

When Ember is a good choice

Choose Ember when many people will work on one app for a long time, when you want a single approach to routing, data and testing, and when stability matters more than novelty. Companies run large products on it for exactly these reasons. Think twice if you are building a tiny static page or a one-off prototype; the structure that helps a large team is overhead there.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does "convention over configuration" mean in Ember?

    Putting a route in app/routes/posts.js is enough for Ember to find and use it. The resolver maps names to file paths.
  2. 2. What does the rule "data down, actions up" describe?

    Arguments flow from parent to child. A child asks for a change by calling an action it received, so one place owns each piece of state.
  3. 3. Which of these is part of a standard Ember app out of the box?

    Ember includes a router, templates and components, services, Ember Data and testing tools. Payments, mobile compilers and CSS frameworks are not part of it.
  4. 4. Which style does this track use for new components?

    Octane style (Glimmer components, tracked properties, the on modifier) is the modern programming model.

Summary

  • Ember is an opinionated framework that bundles a router, templates, components, services, a data layer, tooling and tests.
  • File names and locations are the configuration; the resolver connects names to files.
  • Data flows down as arguments and actions flow up as function calls.
  • Octane is the modern style: Glimmer components, @tracked, {{on}}, and template tag (.gjs) files.
  • It shines for large, long-lived apps with many developers.

Next: Installing Ember and Project Structure