DefaultResolver
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 upApp.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
Parameters:
-
found
Boolean
-
parsedName
Object
knownForType (type) private
Used to iterate all items of a given type.
Parameters:
-
type
String
- the type to search for
lookupDescription (fullName) protected
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
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) Object
public
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
Lookup the controller using resolveOther
Parameters:
-
parsedName
Object
- a parseName object with the parsed fullName lookup string
resolveHelper (parsedName) protected
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
Lookup the model on the Application namespace
Parameters:
-
parsedName
Object
- a parseName object with the parsed fullName lookup string
resolveOther (parsedName) protected
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
Lookup the route using resolveOther
Parameters:
-
parsedName
Object
- a parseName object with the parsed fullName lookup string
resolveTemplate (parsedName) protected
Look up the template in Ember.TEMPLATES
Parameters:
-
parsedName
Object
- a parseName object with the parsed fullName lookup string
resolveView (parsedName) protected
Lookup the view using resolveOther
Parameters:
-
parsedName
Object
- a parseName object with the parsed fullName lookup string
translateToContainerFullname (type, name) private
Converts provided name from the backing namespace into a container lookup name.
Examples:
App.FooBarHelper -> helper:foo-bar App.THelper -> helper:t
useRouterNaming (parsedName) protected
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
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.
https://emberjs.com/api/classes/Ember.DefaultResolver.html