Skip to content

Commit

Permalink
Add Route#viewFor
Browse files Browse the repository at this point in the history
this gives routes a first class way to access view instances.
For example creating a popup from the route as the result of an
event.
  • Loading branch information
stefanpenner committed Jul 4, 2013
1 parent 2f8e0d8 commit ca72e5a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/ember-routing/lib/system/route.js
Expand Up @@ -554,6 +554,16 @@ Ember.Route = Ember.Object.extend({
return controller;
},

/**
Return a new view instance for the given name
@method viewFor
@param {String} name of the view
@return {Ember.View} instance of the view
*/
viewFor: function(name) {
return this.container.lookup('view:' + name);
},
/**
Returns the current model for a given route.
Expand Down
16 changes: 16 additions & 0 deletions packages/ember-routing/tests/system/route_test.js
Expand Up @@ -36,5 +36,21 @@ test("default model utilizes the container to acquire the model factory", functi

return Post;
}
});

test("Route#viewFor", function(){
ok(route.viewFor, 'function is present');

var lookup = {
'view:application': {}
};

route.container = {
lookup: function(fullName) {
return lookup[fullName];
}
};

equal(route.viewFor('unknown'), undefined, 'returns undefined for unknown for lookup');
equal(route.viewFor('application'), lookup['view:application'], 'return the correct view on valid lookup');
});

0 comments on commit ca72e5a

Please sign in to comment.