Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the Ember.Container

Tags:

ember.js

Can anyone explain what the purpose of the Container module is in the latest Ember?

An example of its usage, in the setup and in the start of this test:

module("Ember.View - handlebars integration", {
  setup: function() {
    Ember.lookup = lookup = { Ember: Ember };
    lookup.TemplateTests = TemplateTests = Ember.Namespace.create();

    container = new Ember.Container();
    container.optionsForType('template', { instantiate: false });
  }

test("template view should call the function of the associated template", function() {
  container.register('template', 'testTemplate', Ember.Handlebars.compile("<h1 id='twas-called'>template was called</h1>"));
like image 710
dagda1 Avatar asked Dec 29 '12 20:12

dagda1


People also ask

What is the purpose of Ember?

Ember. js is an open source, free JavaScript client-side framework used for developing web applications. It allows building client side JavaScript applications by providing a complete solution which contains data management and an application flow. The original name of Ember.

What is store in Ember?

The store contains all of the data for records loaded from the server. It is also responsible for creating instances of Model that wrap the individual data for a record, so that they can be bound to in your Handlebars templates.

What is an ember model?

In Ember Data, models are objects that represent the underlying data that your application presents to the user. Note that Ember Data models are a different concept than the model method on Routes, although they share the same name.

Is Ember front end?

Ember. js is one component of a complete front end stack built and supported by the Ember core team.


2 Answers

The goal of the container is to provide a more general-purpose mechanism for describing module dependencies than the ad-hoc approach we had been using.

For example, imagine you want to find the controller for the post route. The default Ember rules are that we would look it up as App.PostController. Before the container, we would just hardcode those rules wherever we needed to do the lookup (using classify and friends).

The container provides a way for us to define those rules in a single place. As a bonus, the rules can be overridden for applications that want a different convention.

So instead of Ember.get(namespace, Ember.String.classify(name) + 'Controller') internally, we now do container.lookup('controller:' + name).

like image 196
Yehuda Katz Avatar answered Sep 17 '22 20:09

Yehuda Katz


Intended for internal use.

Not meant to be public API

https://github.com/emberjs/ember.js/commit/5becdc4467573f80a5c5dbb51d97c6b9239714a8

like image 40
bbs Avatar answered Sep 20 '22 20:09

bbs