v 2.14
Handlebars - templating engine
Ember Data - provides a consistent way to communicate with external APIs & manage application state
Helpers - transforms received data into desired format for Ember Data
Central part of an Ember app
It drives the application state based on the URL
The router displays a template depending on the route
Routes talk to the model to see what the data structure should be for displaying in the template
Routes deal mostly with the DS (data store)
Models represent persistent state.
Models are part of Ember Data which gives you a single store, which is the central repository of models in your application.
Components and routes can ask the store for models, and the store is responsible for knowing how to fetch them. This allows the app to fetch the data once and save it in the store.
They describe how the UI should look
They are the views of an Ember app
Ember uses Handlebars to render HTML
Templates usually correspond to a parent route or a component
Components control how the user interface behaves.
*Components must have dash in their name eg my-post not post
Components consist of two parts:
Components handle all the lifecycle hooks
Controllers behave like a specialized type of Component that is rendered by the router when entering a Route.
The controller receives a single property from the Route – model – which is the return value of the Route's model() method.
Controllers are best used for interaction with a template, usually meant for actions
npm install -g ember-cli
ember new 'app-name'
app
config - configure environment settings
public - contains assets, images & fonts
tests - automated tests
vendor - store frontend dependencies
Generate route - ember g route `route-name`
Generate template - ember g `template-name`
Generate component - ember g `component-name`
Generate controller - ember g controller `controller-name`
Generate model - ember g model `model-name`
Run ember app - ember serve or ember s
Build for production - ember build --env production
1. Create a Route
2. Add functionality (if necessary) to the route file
3. Create a Route Template
4. Add HTML, links and data display to your template
If you want your index to render a different view than just an index view:
Ember models use Ember Data, you need to structure the data of you app by extending the DS.Model
ember g model `model-name`
When you create a component it creates a .js in the components folder and a .hbs file in the templates/components folder. Make sure you component name has a dash in it.
Inside the component's template add what you want to be displayed
Inside the components .js file you want to add whatever logic or actions the component might need.
You can use helpers in Ember to change the displayed data value, so that you do not mutate original data
Example:
helpers/rental-property-type.js
templates/components/rental-listing.hbs
To make components more reusable, make use of the {{yield}} functionality.
The component will then host basic logic and contain a {{yield}} statement after.
Then wherever you chose to render that component, you tell the component what the yield should be.
components/list-filter.hbs
template.hbs where component is being called
Controllers should be used when logic is needed based off the current route, rather than the component.
When should you use a controller?
I your logic and actions do not need to be shared with multiple components inside the same route, don't use a controller.
A Service is an Ember object that lives for the duration of the application, and can be made available in different parts of your application.
Services are useful for features that require shared state or persistent connections. Example uses:
Services are the injectable, you add them to the necessary compnents
The main file that maps all the routes and their child routes, the router finds the corresponding route file (if needed)
The route file by default renders the template of the same name, you can tell the route file to render a different template instead. The route files are the route handler
The route is also where you would set the model needed for data display, and anything the template needs in order to render
Child Routes
To use child routes you nest those routes inside the parent route
Child Routes
If you want separate views for those child routes (meaning they are not just components), you need to create a folder in the templates folder with the name of you parent route, and inside that folder put all the templates needed for the child routes.
Models represent your data structure in ember, they are part of Ember Data which gives you a single store, which is the central repository of models in your application.
Templates are handlebars files that describe how the UI should look.
Templates usually correspond to a parent route or a component
Templates are usually displayed in the following ways:
Components control how the user interface behaves.
Components should host necessary actions and state of the application
Components consist of two parts:
Components handle all the lifecycle hooks
Controllers should be used whenever logic and actions need to be shared between components on the same route
Services are useful for features that require shared state or persistent connections. They are injectable and allow information to be shared with components who need it.
They are similar to a controller but they are not route dependent.
New Models
Change?
Keep
Parent routes
Maybe
Main Templates
Pages (Folders - parent routes)
Main Templates
Pages (Folders - parent routes)
Components
Controllers
Services, helpers, mixins
Do you love