From cd8c15704b7b8754ff69bed0cfe58583110fe7f4 Mon Sep 17 00:00:00 2001 From: Bj Tecu Date: Sun, 22 Aug 2021 13:19:29 -0400 Subject: [PATCH] [CLEANUP] Remove Application Controller Router Properties --- .../components/link-to/routing-angle-test.js | 15 ++-- .../components/link-to/routing-curly-test.js | 15 ++-- .../-internals/routing/lib/system/router.ts | 51 +------------- .../@ember/application/tests/reset_test.js | 9 +-- packages/@ember/deprecated-features/index.ts | 1 - .../tests/routing/decoupled_basic_test.js | 70 +++++-------------- .../ember/tests/routing/model_loading_test.js | 8 --- .../ember/tests/routing/substates_test.js | 69 +++++++++++------- 8 files changed, 73 insertions(+), 165 deletions(-) diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js index fa7e4c22561..70076a8dc4f 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js @@ -1726,16 +1726,11 @@ moduleFor( await this.click('#about-link'); - expectDeprecation(() => { - let currentRouteName = this.applicationInstance - .lookup('controller:application') - .get('currentRouteName'); - assert.notEqual( - currentRouteName, - 'about', - 'link-to should not transition if target is not equal to _self or empty' - ); - }, 'Accessing `currentRouteName` on `controller:application` is deprecated, use the `currentRouteName` property on `service:router` instead.'); + assert.notEqual( + this.appRouter.currentRouteName, + 'about', + 'link-to should not transition if target is not equal to _self or empty' + ); } async [`@test it accepts string/numeric arguments`](assert) { diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js index 2ecf5ae4cf0..b8cc6247317 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js @@ -1848,16 +1848,11 @@ moduleFor( await this.click('#about-link > a'); - expectDeprecation(() => { - let currentRouteName = this.applicationInstance - .lookup('controller:application') - .get('currentRouteName'); - assert.notEqual( - currentRouteName, - 'about', - 'link-to should not transition if target is not equal to _self or empty' - ); - }, 'Accessing `currentRouteName` on `controller:application` is deprecated, use the `currentRouteName` property on `service:router` instead.'); + assert.notEqual( + this.appRouter.currentRouteName, + 'about', + 'link-to should not transition if target is not equal to _self or empty' + ); } async [`@test it accepts string/numeric arguments`](assert) { diff --git a/packages/@ember/-internals/routing/lib/system/router.ts b/packages/@ember/-internals/routing/lib/system/router.ts index 384e5c11c25..09b2bcca505 100644 --- a/packages/@ember/-internals/routing/lib/system/router.ts +++ b/packages/@ember/-internals/routing/lib/system/router.ts @@ -1,13 +1,13 @@ import { privatize as P } from '@ember/-internals/container'; import { OutletState as GlimmerOutletState, OutletView } from '@ember/-internals/glimmer'; -import { computed, get, notifyPropertyChange, set } from '@ember/-internals/metal'; +import { computed, get, set } from '@ember/-internals/metal'; import { FactoryClass, getOwner, Owner } from '@ember/-internals/owner'; import { BucketCache } from '@ember/-internals/routing'; import RouterService from '@ember/-internals/routing/lib/services/router'; import { A as emberA, Evented, Object as EmberObject, typeOf } from '@ember/-internals/runtime'; import Controller from '@ember/controller'; import { assert, deprecate, info } from '@ember/debug'; -import { APP_CTRL_ROUTER_PROPS, ROUTER_EVENTS } from '@ember/deprecated-features'; +import { ROUTER_EVENTS } from '@ember/deprecated-features'; import EmberError from '@ember/error'; import { cancel, once, run, scheduleOnce } from '@ember/runloop'; import { DEBUG } from '@glimmer/env'; @@ -1735,53 +1735,6 @@ function updatePaths(router: EmberRouter) { // actually been entered at that point. return; } - if (APP_CTRL_ROUTER_PROPS) { - if (!('currentPath' in appController)) { - Object.defineProperty(appController, 'currentPath', { - get() { - deprecate( - 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.', - false, - { - id: 'application-controller.router-properties', - until: '4.0.0', - url: - 'https://deprecations.emberjs.com/v3.x#toc_application-controller-router-properties', - for: 'ember-source', - since: { - enabled: '3.10.0-beta.1', - }, - } - ); - return get(router, 'currentPath'); - }, - }); - } - notifyPropertyChange(appController, 'currentPath'); - - if (!('currentRouteName' in appController)) { - Object.defineProperty(appController, 'currentRouteName', { - get() { - deprecate( - 'Accessing `currentRouteName` on `controller:application` is deprecated, use the `currentRouteName` property on `service:router` instead.', - false, - { - id: 'application-controller.router-properties', - until: '4.0.0', - url: - 'https://deprecations.emberjs.com/v3.x#toc_application-controller-router-properties', - for: 'ember-source', - since: { - enabled: '3.10.0-beta.1', - }, - } - ); - return get(router, 'currentRouteName'); - }, - }); - } - notifyPropertyChange(appController, 'currentRouteName'); - } } function didBeginTransition(transition: Transition, router: EmberRouter) { diff --git a/packages/@ember/application/tests/reset_test.js b/packages/@ember/application/tests/reset_test.js index b2f15524e49..6e7c852a59a 100644 --- a/packages/@ember/application/tests/reset_test.js +++ b/packages/@ember/application/tests/reset_test.js @@ -1,5 +1,4 @@ import { run } from '@ember/runloop'; -import { get } from '@ember/-internals/metal'; import Controller from '@ember/controller'; import { Router } from '@ember/-internals/routing'; import { moduleFor, AutobootApplicationTestCase } from 'internal-test-helpers'; @@ -129,9 +128,7 @@ moduleFor( let location = initialRouter.get('location'); assert.equal(location.getURL(), '/one'); - expectDeprecation(() => { - assert.equal(get(initialApplicationController, 'currentPath'), 'one'); - }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); + assert.equal(initialRouter.currentPath, 'one'); this.application.reset(); @@ -160,9 +157,7 @@ moduleFor( ); assert.equal(location.getURL(), '/one'); - expectDeprecation(() => { - assert.equal(get(applicationController, 'currentPath'), 'one'); - }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); + assert.equal(router.currentPath, 'one'); }); } diff --git a/packages/@ember/deprecated-features/index.ts b/packages/@ember/deprecated-features/index.ts index 8170ba67304..5b93040f31c 100644 --- a/packages/@ember/deprecated-features/index.ts +++ b/packages/@ember/deprecated-features/index.ts @@ -4,5 +4,4 @@ // not the version that the feature will be removed. export const ROUTER_EVENTS = !!'4.0.0'; -export const APP_CTRL_ROUTER_PROPS = !!'3.10.0-beta.1'; export const ASSIGN = !!'4.0.0-beta.1'; diff --git a/packages/ember/tests/routing/decoupled_basic_test.js b/packages/ember/tests/routing/decoupled_basic_test.js index 33d1bb89897..175055830b4 100644 --- a/packages/ember/tests/routing/decoupled_basic_test.js +++ b/packages/ember/tests/routing/decoupled_basic_test.js @@ -79,14 +79,6 @@ moduleFor( }); } - get currentPath() { - let currentPath; - expectDeprecation(() => { - currentPath = this.applicationInstance.lookup('controller:application').get('currentPath'); - }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); - return currentPath; - } - async ['@test warn on URLs not included in the route set'](assert) { await this.visit('/'); @@ -95,7 +87,7 @@ moduleFor( ['@test The Homepage'](assert) { return this.visit('/').then(() => { - assert.equal(this.currentPath, 'home', 'currently on the home route'); + assert.equal(this.appRouter.currentPath, 'home', 'currently on the home route'); let text = this.$('.hours').text(); assert.equal(text, 'Hours', 'the home template was rendered'); @@ -109,7 +101,7 @@ moduleFor( return this.visit('/camelot') .then(() => { - assert.equal(this.currentPath, 'camelot'); + assert.equal(this.appRouter.currentPath, 'camelot'); let text = this.$('#camelot').text(); assert.equal(text, 'Is a silly place', 'the camelot template was rendered'); @@ -117,7 +109,7 @@ moduleFor( return this.visit('/'); }) .then(() => { - assert.equal(this.currentPath, 'home'); + assert.equal(this.appRouter.currentPath, 'home'); let text = this.$('.hours').text(); assert.equal(text, 'Hours', 'the home template was rendered'); @@ -708,12 +700,12 @@ moduleFor( 1, 'The home template was rendered' ); - assert.equal(this.currentPath, 'home'); + assert.equal(this.appRouter.currentPath, 'home'); }); } ['@test Redirecting from the middle of a route aborts the remainder of the routes'](assert) { - assert.expect(5); + assert.expect(4); this.router.map(function () { this.route('home'); @@ -750,13 +742,7 @@ moduleFor( return this.visit('/').then(() => { let router = this.applicationInstance.lookup('router:main'); this.handleURLAborts(assert, '/foo/bar/baz'); - let currentPath; - expectDeprecation(() => { - currentPath = this.applicationInstance - .lookup('controller:application') - .get('currentPath'); - }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); - assert.equal(currentPath, 'home'); + assert.equal(router.currentPath, 'home'); assert.equal(router.get('location').getURL(), '/home'); }); } @@ -764,7 +750,7 @@ moduleFor( ['@test Redirecting to the current target in the middle of a route does not abort initial routing']( assert ) { - assert.expect(7); + assert.expect(6); this.router.map(function () { this.route('home'); @@ -805,13 +791,7 @@ moduleFor( return this.visit('/foo/bar/baz').then(() => { assert.ok(true, '/foo/bar/baz has been handled'); - let currentPath; - expectDeprecation(() => { - currentPath = this.applicationInstance - .lookup('controller:application') - .get('currentPath'); - }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); - assert.equal(currentPath, 'foo.bar.baz'); + assert.equal(this.appRouter.currentPath, 'foo.bar.baz'); assert.equal(successCount, 1, 'transitionTo success handler was called once'); }); } @@ -819,7 +799,7 @@ moduleFor( ['@test Redirecting to the current target with a different context aborts the remainder of the routes']( assert ) { - assert.expect(7); + assert.expect(6); this.router.map(function () { this.route('home'); @@ -860,13 +840,7 @@ moduleFor( return this.visit('/').then(() => { this.handleURLAborts(assert, '/foo/bar/1/baz'); - let currentPath; - expectDeprecation(() => { - currentPath = this.applicationInstance - .lookup('controller:application') - .get('currentPath'); - }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); - assert.equal(currentPath, 'foo.bar.baz'); + assert.equal(this.appRouter.currentPath, 'foo.bar.baz'); assert.equal( this.applicationInstance.lookup('router:main').get('location').getURL(), '/foo/bar/2/baz' @@ -901,19 +875,11 @@ moduleFor( return this.visit('/foo/bar/baz').then(() => { assert.ok(true, '/foo/bar/baz has been handled'); - let applicationController = this.applicationInstance.lookup('controller:application'); let router = this.applicationInstance.lookup('router:main'); - let currentPath; - expectDeprecation(() => { - currentPath = applicationController.get('currentPath'); - }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); - assert.equal(currentPath, 'foo.bar.baz'); + assert.equal(router.currentPath, 'foo.bar.baz'); run(() => router.send('goToQux')); - expectDeprecation(() => { - currentPath = applicationController.get('currentPath'); - }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); - assert.equal(currentPath, 'foo.qux'); + assert.equal(router.currentPath, 'foo.qux'); assert.equal(router.get('location').getURL(), '/foo/qux'); }); } @@ -1405,10 +1371,10 @@ moduleFor( }); } - ['@test currentRouteName is a property installed on ApplicationController that can be used in transitionTo']( + ['@test currentRouteName is a property installed on Router that can be used in transitionTo']( assert ) { - assert.expect(36); + assert.expect(24); this.router.map(function () { this.route('index', { path: '/' }); @@ -1424,17 +1390,15 @@ moduleFor( }); return this.visit('/').then(() => { - let appController = this.applicationInstance.lookup('controller:application'); let router = this.applicationInstance.lookup('router:main'); function transitionAndCheck(path, expectedPath, expectedRouteName) { if (path) { run(router, 'transitionTo', path); } - expectDeprecation(() => { - assert.equal(appController.get('currentPath'), expectedPath); - assert.equal(appController.get('currentRouteName'), expectedRouteName); - }, /Accessing `(currentPath|currentRouteName)` on `controller:application` is deprecated, use the `(currentPath|currentRouteName)` property on `service:router` instead\./); + + assert.equal(router.currentPath, expectedPath); + assert.equal(router.currentRouteName, expectedRouteName); } transitionAndCheck(null, 'index', 'index'); diff --git a/packages/ember/tests/routing/model_loading_test.js b/packages/ember/tests/routing/model_loading_test.js index afced00f49c..81f4bc23186 100644 --- a/packages/ember/tests/routing/model_loading_test.js +++ b/packages/ember/tests/routing/model_loading_test.js @@ -56,14 +56,6 @@ moduleFor( }); } - get currentPath() { - let currentPath; - expectDeprecation(() => { - currentPath = this.applicationInstance.lookup('controller:application').get('currentPath'); - }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); - return currentPath; - } - async ['@test warn on URLs not included in the route set'](assert) { await this.visit('/'); diff --git a/packages/ember/tests/routing/substates_test.js b/packages/ember/tests/routing/substates_test.js index 13330e7d0c1..494a3bd5542 100644 --- a/packages/ember/tests/routing/substates_test.js +++ b/packages/ember/tests/routing/substates_test.js @@ -145,7 +145,7 @@ moduleFor( }); assert.ok( - this.currentPath !== 'loading', + this.appRouter.currentPath !== 'loading', ` loading state not entered ` @@ -188,7 +188,7 @@ moduleFor( assert.equal(text, 'DUMMY', `dummy template has been rendered`); }); - assert.equal(this.currentPath, 'loading', `loading state entered`); + assert.equal(this.appRouter.currentPath, 'loading', `loading state entered`); deferred.resolve(); return promise; @@ -249,7 +249,7 @@ moduleFor( ); }); - assert.equal(this.currentPath, 'loading', `loading state entered`); + assert.equal(this.appRouter.currentPath, 'loading', `loading state entered`); assert.equal( this.currentURL, '/dummy?qux=updated', @@ -268,7 +268,7 @@ moduleFor( } ['@test Enter child-loading route with correct query parameters'](assert) { - assert.expect(9); + assert.expect(8); let deferred = RSVP.defer(); this.router.map(function () { @@ -326,12 +326,18 @@ moduleFor( ); }); - assert.equal(this.currentPath, 'parent.child_loading', `child loading state entered`); + assert.equal( + this.appRouter.currentPath, + 'parent.child_loading', + `child loading state entered` + ); + assert.equal( this.currentURL, '/parent/child?qux=updated', `during child loading, url reflect the correct state` ); + assert.equal( this.getController('parent').qux, 'updated', @@ -724,14 +730,6 @@ moduleFor( return this.applicationInstance.lookup(`controller:${name}`); } - get currentPath() { - let currentPath; - expectDeprecation(() => { - currentPath = this.getController('application').get('currentPath'); - }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); - return currentPath; - } - async ['@test ApplicationRoute#currentPath reflects loading state path'](assert) { await this.visit('/'); @@ -752,13 +750,21 @@ moduleFor( text = this.$('#app').text(); assert.equal(text, 'GRANDMA MOM', `Grandma.mom loaded text is displayed`); - assert.equal(this.currentPath, 'grandma.mom.index', `currentPath reflects final state`); + assert.equal( + this.appRouter.currentPath, + 'grandma.mom.index', + `currentPath reflects final state` + ); }); let text = this.$('#app').text(); assert.equal(text, 'GRANDMA GRANDMALOADING', `Grandma.mom loading text displayed`); - assert.equal(this.currentPath, 'grandma.loading', `currentPath reflects loading state`); + assert.equal( + this.appRouter.currentPath, + 'grandma.loading', + `currentPath reflects loading state` + ); momDeferred.resolve(); @@ -801,17 +807,17 @@ moduleFor( ); let promise = this.visit('/grandma/mom/sally'); - assert.equal(this.currentPath, 'index', 'Initial route fully loaded'); + assert.equal(this.appRouter.currentPath, 'index', 'Initial route fully loaded'); sallyDeferred.resolve(); promise .then(() => { - assert.equal(this.currentPath, 'grandma.mom.sally', 'transition completed'); + assert.equal(this.appRouter.currentPath, 'grandma.mom.sally', 'transition completed'); let visit = this.visit('/grandma/puppies'); assert.equal( - this.currentPath, + this.appRouter.currentPath, 'grandma.mom.sally', 'still in initial state because the only loading state is above the pivot route' ); @@ -821,7 +827,7 @@ moduleFor( .then(() => { runTask(() => puppiesDeferred.resolve()); - assert.equal(this.currentPath, 'grandma.puppies', 'Finished transition'); + assert.equal(this.appRouter.currentPath, 'grandma.puppies', 'Finished transition'); }); return promise; @@ -855,7 +861,7 @@ moduleFor( step(assert, 3, 'App finished loading'); assert.equal(this.$('#app').text(), 'GRANDMA ERROR: did it broke?', 'error bubbles'); - assert.equal(this.currentPath, 'grandma.error', 'Initial route fully loaded'); + assert.equal(this.appRouter.currentPath, 'grandma.error', 'Initial route fully loaded'); } async [`@test Non-bubbled errors that re-throw aren't swallowed`](assert) { @@ -1047,7 +1053,7 @@ moduleFor( 'the more specifically named mome error substate was entered over the other error route' ); - assert.equal(this.currentPath, 'grandma.mom_error', 'Initial route fully loaded'); + assert.equal(this.appRouter.currentPath, 'grandma.mom_error', 'Initial route fully loaded'); } async ['@test Slow promises waterfall on startup'](assert) { @@ -1146,13 +1152,18 @@ moduleFor( ); await this.visit('/grandma/mom/sally'); - assert.equal(this.currentPath, 'grandma.mom.sally', 'Initial route fully loaded'); + assert.equal(this.appRouter.currentPath, 'grandma.mom.sally', 'Initial route fully loaded'); let promise = runTask(() => this.visit('/grandma/puppies')).then(() => { - assert.equal(this.currentPath, 'grandma.puppies', 'Finished transition'); + assert.equal(this.appRouter.currentPath, 'grandma.puppies', 'Finished transition'); }); - assert.equal(this.currentPath, 'grandma.loading', `in pivot route's child loading state`); + assert.equal( + this.appRouter.currentPath, + 'grandma.loading', + `in pivot route's child loading state` + ); + deferred.resolve(); return promise; @@ -1261,15 +1272,19 @@ moduleFor( ); let promise = runTask(() => this.visit('/grandma')).then(() => { - assert.equal(this.currentPath, 'memere.index', 'Transition should be complete'); + assert.equal(this.appRouter.currentPath, 'memere.index', 'Transition should be complete'); }); let memereController = this.getController('memere'); - assert.equal(this.currentPath, 'memere.loading', 'Initial route should be loading'); + assert.equal(this.appRouter.currentPath, 'memere.loading', 'Initial route should be loading'); memereController.set('test', 3); - assert.equal(this.currentPath, 'memere.loading', 'Initial route should still be loading'); + assert.equal( + this.appRouter.currentPath, + 'memere.loading', + 'Initial route should still be loading' + ); assert.equal( memereController.get('test'),