W3cubDocs

/Ember.js

Ember.DefaultResolver Class

PUBLIC

Extends: Ember.Object

Defined in: packages/ember-application/lib/system/resolver.js:33

Module: ember-application

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

_logLookup (found, parsedName) private

Defined in packages/ember-application/lib/system/resolver.js:386

Parameters:

found Boolean
parsedName Object

knownForType (type) private

Defined in packages/ember-application/lib/system/resolver.js:410

Used to iterate all items of a given type.

Parameters:

type String
the type to search for

lookupDescription (fullName) protected

Defined in packages/ember-application/lib/system/resolver.js:242

Returns a human-readable description for a fullName. Used by the Application namespace in assertions to describe the precise name of the class that Ember is looking for, rather than container keys.

Parameters:

fullName String
the lookup string

parseName (fullName) protected

Defined in packages/ember-application/lib/system/resolver.js:185

Convert the string name of the form 'type:name' to a Javascript object with the parsed aspects of the name broken out.

Parameters:

fullName String
the lookup string

resolve (fullName) Objectpublic

Defined in packages/ember-application/lib/system/resolver.js:153

This method is called via the container's resolver method. It parses the provided fullName and then looks up and returns the appropriate template or class.

Parameters:

fullName String
the lookup string

Returns:

Object
the resolved factory

resolveController (parsedName) protected

Defined in packages/ember-application/lib/system/resolver.js:315

Lookup the controller using resolveOther

Parameters:

parsedName Object
a parseName object with the parsed fullName lookup string

resolveHelper (parsedName) protected

Defined in packages/ember-application/lib/system/resolver.js:354

Look up the specified object (from parsedName) on the appropriate namespace (usually on the Application)

Parameters:

parsedName Object
a parseName object with the parsed fullName lookup string

resolveModel (parsedName) protected

Defined in packages/ember-application/lib/system/resolver.js:340

Lookup the model on the Application namespace

Parameters:

parsedName Object
a parseName object with the parsed fullName lookup string

resolveOther (parsedName) protected

Defined in packages/ember-application/lib/system/resolver.js:366

Look up the specified object (from parsedName) on the appropriate namespace (usually on the Application)

Parameters:

parsedName Object
a parseName object with the parsed fullName lookup string

resolveRoute (parsedName) protected

Defined in packages/ember-application/lib/system/resolver.js:327

Lookup the route using resolveOther

Parameters:

parsedName Object
a parseName object with the parsed fullName lookup string

resolveTemplate (parsedName) protected

Defined in packages/ember-application/lib/system/resolver.js:288

Look up the template in Ember.TEMPLATES

Parameters:

parsedName Object
a parseName object with the parsed fullName lookup string

resolveView (parsedName) protected

Defined in packages/ember-application/lib/system/resolver.js:302

Lookup the view using resolveOther

Parameters:

parsedName Object
a parseName object with the parsed fullName lookup string

translateToContainerFullname (type, name) private

Defined in packages/ember-application/lib/system/resolver.js:437

Converts provided name from the backing namespace into a container lookup name.

Examples:

App.FooBarHelper -> helper:foo-bar App.THelper -> helper:t

Parameters:

type String
name String

useRouterNaming (parsedName) protected

Defined in packages/ember-application/lib/system/resolver.js:273

Given a parseName object (output from parseName), apply the conventions expected by Ember.Router

Parameters:

parsedName Object
a parseName object with the parsed fullName lookup string

namespacepublic

Defined in packages/ember-application/lib/system/resolver.js:106

This will be set to the Application instance when it is created.

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