Skip to content

Commit

Permalink
[BUGFIX beta] deprecate this.resource() in Router.map(), use this.rou…
Browse files Browse the repository at this point in the history
…te('name', { resetNamespace: true }) instead
  • Loading branch information
jayphelps committed Jun 19, 2015
1 parent 0df7beb commit 78c22ee
Show file tree
Hide file tree
Showing 20 changed files with 155 additions and 151 deletions.
2 changes: 1 addition & 1 deletion packages/ember-application/lib/ext/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ControllerMixin.reopen({
this.get('controllers.post'); // instance of App.PostController
```
Given that you have a nested controller (nested resource):
Given that you have a nested controller (nested routes):
```javascript
App.CommentsNewController = Ember.ObjectController.extend({
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-application/tests/system/logging_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ QUnit.module('Ember.Application – logging of generated classes', {
});

App.Router.map(function() {
this.resource('posts');
this.route('posts', { resetNamespace: true });
});

App.deferReadiness();
Expand Down Expand Up @@ -161,7 +161,7 @@ QUnit.module('Ember.Application – logging of view lookups', {
});

App.Router.map(function() {
this.resource('posts');
this.route('posts', { resetNamespace: true });
});

App.deferReadiness();
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-routing-htmlbars/lib/keywords/link-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ import merge from 'ember-metal/merge';
```javascript
App.Router.map(function() {
this.resource("photoGallery", {path: "hamster-photos/:photo_id"});
this.route("photoGallery", {path: "hamster-photos/:photo_id"});
});
```
Expand All @@ -172,7 +172,7 @@ import merge from 'ember-metal/merge';
```javascript
App.Router.map(function() {
this.resource("photoGallery", {path: "hamster-photos/:photo_id"}, function() {
this.route("photoGallery", { path: "hamster-photos/:photo_id" }, function() {
this.route("comment", {path: "comments/:comment_id"});
});
});
Expand All @@ -199,7 +199,7 @@ import merge from 'ember-metal/merge';
```javascript
App.Router.map(function() {
this.resource("photoGallery", {path: "hamster-photos/:photo_id"});
this.route("photoGallery", { path: "hamster-photos/:photo_id" });
});
```
Expand Down
12 changes: 6 additions & 6 deletions packages/ember-routing/lib/ext/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ ControllerMixin.reopen({
```
Multiple models will be applied last to first recursively up the
resource tree.
route tree.
```javascript
App.Router.map(function() {
this.resource('blogPost', {path:':blogPostId'}, function() {
this.resource('blogComment', {path: ':blogCommentId'});
this.route('blogPost', { path: ':blogPostId' }, function() {
this.route('blogComment', { path: ':blogCommentId', resetNamespace: true });
});
});
Expand Down Expand Up @@ -156,12 +156,12 @@ ControllerMixin.reopen({
```
Multiple models will be applied last to first recursively up the
resource tree.
route tree.
```javascript
App.Router.map(function() {
this.resource('blogPost', {path:':blogPostId'}, function() {
this.resource('blogComment', {path: ':blogCommentId'});
this.route('blogPost', { path: ':blogPostId' }, function() {
this.route('blogComment', { path: ':blogCommentId', resetNamespace: true });
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-routing/lib/location/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { getHash } from 'ember-routing/location/util';
```javascript
App.Router.map(function() {
this.resource('posts', function() {
this.route('posts', function() {
this.route('new');
});
});
Expand All @@ -47,7 +47,7 @@ import { getHash } from 'ember-routing/location/util';
```javascript
App.Router.map(function() {
this.resource('posts', function() {
this.route('posts', function() {
this.route('new');
});
});
Expand Down Expand Up @@ -75,7 +75,7 @@ import { getHash } from 'ember-routing/location/util';
```javascript
App.Router.map(function() {
this.resource('posts', function() {
this.route('posts', function() {
this.route('new');
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/ember-routing/lib/system/dsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ DSL.prototype = {
}

options.resetNamespace = true;
Ember.deprecate('this.resource() is deprecated. Use this.route(\'name\', { resetNamespace: true }, function () {}) instead.');
this.route(name, options, callback);
},

Expand Down
30 changes: 15 additions & 15 deletions packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,12 +886,12 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
```
Multiple models will be applied last to first recursively up the
resource tree.
route tree.
```javascript
App.Router.map(function() {
this.resource('blogPost', { path:':blogPostId' }, function() {
this.resource('blogComment', { path: ':blogCommentId' });
this.route('blogPost', { path:':blogPostId' }, function() {
this.route('blogComment', { path: ':blogCommentId', resetNamespace: true });
});
});
Expand Down Expand Up @@ -949,7 +949,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
```javascript
App.Router.map(function() {
this.resource('articles', { path: '/articles' }, function() {
this.route('articles', { path: '/articles' }, function() {
this.route('new');
});
});
Expand All @@ -969,8 +969,8 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
App.Router.map(function() {
this.route('index');
this.resource('breakfast', { path: ':breakfastId' }, function() {
this.resource('cereal', { path: ':cerealId' });
this.route('breakfast', { path: ':breakfastId' }, function() {
this.route('cereal', { path: ':cerealId', resetNamespace: true });
});
});
Expand All @@ -990,7 +990,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
```javascript
App.Router.map(function() {
this.resource('fruits', function() {
this.route('fruits', function() {
this.route('apples');
});
});
Expand Down Expand Up @@ -1395,7 +1395,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
```javascript
App.Router.map(function() {
this.resource('post', { path: '/posts/:post_id' });
this.route('post', { path: '/posts/:post_id' });
});
```
Expand Down Expand Up @@ -1551,7 +1551,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
```javascript
App.Router.map(function() {
this.resource('post', { path: '/posts/:post_id' });
this.route('post', { path: '/posts/:post_id' });
});
App.PostRoute = Ember.Route.extend({
Expand Down Expand Up @@ -1648,7 +1648,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
```javascript
App.Router.map(function() {
this.resource('post', { path: '/posts/:post_id' });
this.route('post', { path: '/posts/:post_id' });
});
```
Expand Down Expand Up @@ -1759,14 +1759,14 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
```javascript
App.Router.map(function() {
this.resource('post', { path: '/post/:post_id' }, function() {
this.resource('comments');
this.route('post', { path: '/post/:post_id' }, function() {
this.route('comments', { resetNamespace: true });
});
});
App.CommentsRoute = Ember.Route.extend({
afterModel: function() {
this.set('post', this.modelFor('post'));
this.set('post', this.modelFor('post'));
}
});
```
Expand Down Expand Up @@ -1837,7 +1837,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
```javascript
Router.map(function() {
this.resource('photos');
this.route('photos');
});
```
Expand Down Expand Up @@ -1902,7 +1902,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
// router
Router.map(function() {
this.route('index');
this.resource('post', { path: '/posts/:post_id' });
this.route('post', { path: '/posts/:post_id' });
});
```
Expand Down
8 changes: 4 additions & 4 deletions packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var EmberRouter = EmberObject.extend(Evented, {
});

function generateDSL() {
this.resource('application', { path: '/', overrideNameAssertion: true }, function() {
this.route('application', { path: '/', resetNamespace: true, overrideNameAssertion: true }, function() {
for (var i=0; i < dslCallbacks.length; i++) {
dslCallbacks[i].call(this);
}
Expand Down Expand Up @@ -918,13 +918,13 @@ EmberRouter.reopenClass({

/**
The `Router.map` function allows you to define mappings from URLs to routes
and resources in your application. These mappings are defined within the
supplied callback function using `this.resource` and `this.route`.
in your application. These mappings are defined within the
supplied callback function using `this.route`.
```javascript
App.Router.map(function(){
this.route('about');
this.resource('article');
this.route('article', { resetNamespace: true });
});
```
Expand Down
7 changes: 5 additions & 2 deletions packages/ember-routing/tests/system/dsl_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ QUnit.module('Ember Router DSL', {
});

QUnit.test('should fail when using a reserved route name', function() {
expectDeprecation('this.resource() is deprecated. Use this.route(\'name\', { resetNamespace: true }, function () {}) instead.');
var reservedNames = ['array', 'basic', 'object', 'application'];

expect(reservedNames.length * 2);
expect((reservedNames.length * 2) + 1);

reservedNames.forEach(function(reservedName) {
expectAssertion(function() {
Expand All @@ -38,12 +39,14 @@ QUnit.test('should fail when using a reserved route name', function() {

var router = Router.create();
router._initRouterJs();
}, '\'' + reservedName + '\' cannot be used as a resource name.');
}, `'${reservedName}' cannot be used as a resource name.`);

});
});

QUnit.test('should reset namespace if nested with resource', function() {
expectDeprecation('this.resource() is deprecated. Use this.route(\'name\', { resetNamespace: true }, function () {}) instead.');

Router = Router.map(function() {
this.resource('bleep', function() {
this.resource('bloop', function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-runtime/lib/mixins/action_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ var ActionHandler = Mixin.create({
```js
App.Router.map(function() {
this.resource("album", function() {
this.route("album", function() {
this.route("song");
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-testing/tests/helpers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ QUnit.module('ember-testing routing helpers', {
});

App.Router.map(function() {
this.resource('posts', function() {
this.route('posts', { resetNamespace: true }, function() {
this.route('new');
});
});
Expand Down Expand Up @@ -842,7 +842,7 @@ QUnit.module('ember-testing async router', {
});

App.Router.map(function() {
this.resource('user', function() {
this.route('user', { resetNamespace: true }, function() {
this.route('profile');
this.route('edit');
});
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-testing/tests/integration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ QUnit.module('ember-testing Integration', {
});

App.Router.map(function() {
this.resource('people', { path: '/' });
this.route('people', { path: '/' });
});

App.PeopleRoute = EmberRoute.extend({
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-views/lib/views/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Ember.TEMPLATES = {};
});
```
If you have nested resources, your Handlebars template will look like this:
If you have nested routes, your Handlebars template will look like this:
```html
<script type='text/x-handlebars' data-template-name='posts/new'>
Expand Down
Loading

0 comments on commit 78c22ee

Please sign in to comment.