From 78c22ee744e8cd082d5ba95ea491ee9824c5b1dd Mon Sep 17 00:00:00 2001 From: Jay Phelps Date: Fri, 19 Jun 2015 11:24:25 -0700 Subject: [PATCH] [BUGFIX beta] deprecate this.resource() in Router.map(), use this.route('name', { resetNamespace: true }) instead --- .../ember-application/lib/ext/controller.js | 2 +- .../tests/system/logging_test.js | 4 +- .../lib/keywords/link-to.js | 6 +- packages/ember-routing/lib/ext/controller.js | 12 +- packages/ember-routing/lib/location/api.js | 6 +- packages/ember-routing/lib/system/dsl.js | 1 + packages/ember-routing/lib/system/route.js | 30 ++--- packages/ember-routing/lib/system/router.js | 8 +- .../ember-routing/tests/system/dsl_test.js | 7 +- .../lib/mixins/action_handler.js | 2 +- packages/ember-testing/tests/helpers_test.js | 4 +- .../ember-testing/tests/integration_test.js | 2 +- packages/ember-views/lib/views/view.js | 2 +- packages/ember/tests/helpers/link_to_test.js | 34 +++--- .../link_to_with_query_params_test.js | 8 +- packages/ember/tests/routing/basic_test.js | 110 +++++++++--------- .../ember/tests/routing/query_params_test.js | 16 +-- ..._dependent_state_with_query_params_test.js | 16 +-- .../overlapping_query_params_test.js | 4 +- .../ember/tests/routing/substates_test.js | 32 ++--- 20 files changed, 155 insertions(+), 151 deletions(-) diff --git a/packages/ember-application/lib/ext/controller.js b/packages/ember-application/lib/ext/controller.js index 381a83cac77..739f095c340 100644 --- a/packages/ember-application/lib/ext/controller.js +++ b/packages/ember-application/lib/ext/controller.js @@ -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({ diff --git a/packages/ember-application/tests/system/logging_test.js b/packages/ember-application/tests/system/logging_test.js index 0f51e2f4cfb..f22298a244c 100644 --- a/packages/ember-application/tests/system/logging_test.js +++ b/packages/ember-application/tests/system/logging_test.js @@ -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(); @@ -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(); diff --git a/packages/ember-routing-htmlbars/lib/keywords/link-to.js b/packages/ember-routing-htmlbars/lib/keywords/link-to.js index 64fd4ff035b..a2b1faeb5ac 100644 --- a/packages/ember-routing-htmlbars/lib/keywords/link-to.js +++ b/packages/ember-routing-htmlbars/lib/keywords/link-to.js @@ -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"}); }); ``` @@ -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"}); }); }); @@ -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" }); }); ``` diff --git a/packages/ember-routing/lib/ext/controller.js b/packages/ember-routing/lib/ext/controller.js index 67c76ae9eaf..f3dd315ca6e 100644 --- a/packages/ember-routing/lib/ext/controller.js +++ b/packages/ember-routing/lib/ext/controller.js @@ -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 }); }); }); @@ -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 }); }); }); diff --git a/packages/ember-routing/lib/location/api.js b/packages/ember-routing/lib/location/api.js index cce4ab1f3a2..addd354987b 100644 --- a/packages/ember-routing/lib/location/api.js +++ b/packages/ember-routing/lib/location/api.js @@ -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'); }); }); @@ -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'); }); }); @@ -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'); }); }); diff --git a/packages/ember-routing/lib/system/dsl.js b/packages/ember-routing/lib/system/dsl.js index 66281bf3a54..a3183fea969 100644 --- a/packages/ember-routing/lib/system/dsl.js +++ b/packages/ember-routing/lib/system/dsl.js @@ -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); }, diff --git a/packages/ember-routing/lib/system/route.js b/packages/ember-routing/lib/system/route.js index 5f93bff5ab0..b42d56d8b81 100644 --- a/packages/ember-routing/lib/system/route.js +++ b/packages/ember-routing/lib/system/route.js @@ -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 }); }); }); @@ -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'); }); }); @@ -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 }); }); }); @@ -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'); }); }); @@ -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' }); }); ``` @@ -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({ @@ -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' }); }); ``` @@ -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')); } }); ``` @@ -1837,7 +1837,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { ```javascript Router.map(function() { - this.resource('photos'); + this.route('photos'); }); ``` @@ -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' }); }); ``` diff --git a/packages/ember-routing/lib/system/router.js b/packages/ember-routing/lib/system/router.js index bd0fa474441..c002de6a146 100644 --- a/packages/ember-routing/lib/system/router.js +++ b/packages/ember-routing/lib/system/router.js @@ -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); } @@ -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 }); }); ``` diff --git a/packages/ember-routing/tests/system/dsl_test.js b/packages/ember-routing/tests/system/dsl_test.js index 9676730c0e3..7bb4d80fab5 100644 --- a/packages/ember-routing/tests/system/dsl_test.js +++ b/packages/ember-routing/tests/system/dsl_test.js @@ -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() { @@ -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() { diff --git a/packages/ember-runtime/lib/mixins/action_handler.js b/packages/ember-runtime/lib/mixins/action_handler.js index 74aadd765de..581d3f7a51d 100644 --- a/packages/ember-runtime/lib/mixins/action_handler.js +++ b/packages/ember-runtime/lib/mixins/action_handler.js @@ -116,7 +116,7 @@ var ActionHandler = Mixin.create({ ```js App.Router.map(function() { - this.resource("album", function() { + this.route("album", function() { this.route("song"); }); }); diff --git a/packages/ember-testing/tests/helpers_test.js b/packages/ember-testing/tests/helpers_test.js index 9bd7599efaa..35a9e4a3185 100644 --- a/packages/ember-testing/tests/helpers_test.js +++ b/packages/ember-testing/tests/helpers_test.js @@ -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'); }); }); @@ -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'); }); diff --git a/packages/ember-testing/tests/integration_test.js b/packages/ember-testing/tests/integration_test.js index 8647fd240b5..068dcea08e7 100644 --- a/packages/ember-testing/tests/integration_test.js +++ b/packages/ember-testing/tests/integration_test.js @@ -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({ diff --git a/packages/ember-views/lib/views/view.js b/packages/ember-views/lib/views/view.js index aa8a4595c82..61687c7eb94 100644 --- a/packages/ember-views/lib/views/view.js +++ b/packages/ember-views/lib/views/view.js @@ -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