W3cubDocs

/Ember.js

Ember.DefaultResolver (public)

Extends: Ember.Object
Defined in: packages/ember-application/lib/system/resolver.js:35
Module: ember

The DefaultResolver defines the default lookup rules to resolve container lookups before consulting the container for registered items:

  • templates are looked up on Ember.TEMPLATES
  • other names are looked up on the application after converting the name. For example, controller:post looks up App.PostController by default.
  • there are some nuances (see examples below)

How Resolving Works

The container calls this object's resolve method with the fullName argument.

It first parses the fullName into an object using parseName.

Then it checks for the presence of a type-specific instance method of the form resolve[Type] and calls it if it exists. For example if it was resolving 'template:post', it would call the resolveTemplate method.

Its last resort is to call the resolveOther method.

The methods of this object are designed to be easy to override in a subclass. For example, you could enhance how a template is resolved like so:

App = Ember.Application.create({
  Resolver: Ember.DefaultResolver.extend({
    resolveTemplate: function(parsedName) {
      let resolvedTemplate = this._super(parsedName);
      if (resolvedTemplate) { return resolvedTemplate; }
      return Ember.TEMPLATES['not_found'];
    }
  })
});

Some examples of how names are resolved:

'template:post'           //=> Ember.TEMPLATES['post']
'template:posts/byline'   //=> Ember.TEMPLATES['posts/byline']
'template:posts.byline'   //=> Ember.TEMPLATES['posts/byline']
'template:blogPost'       //=> Ember.TEMPLATES['blogPost']
                          //   OR
                          //   Ember.TEMPLATES['blog_post']
'controller:post'         //=> App.PostController
'controller:posts.index'  //=> App.PostsIndexController
'controller:blog/post'    //=> Blog.PostController
'controller:basic'        //=> Ember.Controller
'route:post'              //=> App.PostRoute
'route:posts.index'       //=> App.PostsIndexRoute
'route:blog/post'         //=> Blog.PostRoute
'route:basic'             //=> Ember.Route
'view:post'               //=> App.PostView
'view:posts.index'        //=> App.PostsIndexView
'view:blog/post'          //=> Blog.PostView
'view:basic'              //=> Ember.View
'foo:post'                //=> App.PostFoo
'model:post'              //=> App.Post

Methods

Properties

Events

No documented items

© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://emberjs.com/api/ember/2.14/classes/Ember.DefaultResolver