Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

ember.js - What is the purpose of the Ember.Container

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>"));
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...