Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLEANUP] Remove deprecated routing.transition-methods #20413

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { moduleFor, ApplicationTestCase, strip } from 'internal-test-helpers';
import { ENV } from '@ember/-internals/environment';
import Controller from '@ember/controller';
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import { Component } from '@ember/-internals/glimmer';
import { tracked } from '@ember/-internals/metal';
import { set } from '@ember/object';
Expand Down Expand Up @@ -498,10 +499,10 @@ moduleFor(
this.add(
'route:index',
Route.extend({
router: service(),

activate() {
expectDeprecation(() => {
this.transitionTo('a');
}, /Calling transitionTo on a route is deprecated/);
this.router.transitionTo('a');
},
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { A as emberA } from '@ember/array';
import { RSVP } from '@ember/-internals/runtime';
import Route from '@ember/routing/route';
import NoneLocation from '@ember/routing/none-location';
import { service } from '@ember/service';
import Engine from '@ember/engine';
import { DEBUG } from '@glimmer/env';
import { compile } from '../../../utils/helpers';
Expand Down Expand Up @@ -1798,10 +1799,9 @@ moduleFor(
this.add(
'route:parent',
class extends Route {
@service router;
afterModel() {
expectDeprecation(() => {
this.transitionTo('parent.child');
}, /Calling transitionTo on a route is deprecated/);
this.router.transitionTo('parent.child');
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { A as emberA } from '@ember/array';
import { RSVP } from '@ember/-internals/runtime';
import Route from '@ember/routing/route';
import NoneLocation from '@ember/routing/none-location';
import { service } from '@ember/service';
import Engine from '@ember/engine';
import { DEBUG } from '@glimmer/env';
import { compile } from '../../../utils/helpers';
Expand Down Expand Up @@ -1716,10 +1717,9 @@ moduleFor(
this.add(
'route:parent',
class extends Route {
@service router;
afterModel() {
expectDeprecation(() => {
this.transitionTo('parent.child');
}, /Calling transitionTo on a route is deprecated/);
this.router.transitionTo('parent.child');
}
}
);
Expand Down
20 changes: 8 additions & 12 deletions packages/@ember/application/tests/visit_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,19 @@ moduleFor(
this.add(
'route:a',
Route.extend({
router: service(),
afterModel() {
expectDeprecation(() => {
this.replaceWith('b', 'zomg');
}, /Calling replaceWith on a route is deprecated/);
this.router.replaceWith('b', 'zomg');
},
})
);

this.add(
'route:b',
Route.extend({
router: service(),
afterModel(params) {
expectDeprecation(() => {
this.transitionTo('c', params.b);
}, /Calling transitionTo on a route is deprecated/);
this.router.transitionTo('c', params.b);
},
})
);
Expand Down Expand Up @@ -325,21 +323,19 @@ moduleFor(
this.add(
'route:a',
Route.extend({
router: service(),
afterModel() {
expectDeprecation(() => {
this.replaceWith('b', 'zomg');
}, /Calling replaceWith on a route is deprecated/);
this.router.replaceWith('b', 'zomg');
},
})
);

this.add(
'route:b',
Route.extend({
router: service(),
afterModel(params) {
expectDeprecation(() => {
this.transitionTo('c', params.b);
}, /Calling transitionTo on a route is deprecated/);
this.router.transitionTo('c', params.b);
},
})
);
Expand Down
29 changes: 0 additions & 29 deletions packages/@ember/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { inject as metalInject } from '@ember/-internals/metal';
import type { DecoratorPropertyDescriptor, ElementDescriptor } from '@ember/-internals/metal';
import Mixin from '@ember/object/mixin';
import type { RouteArgs } from '@ember/routing/-internals';
import { deprecateTransitionMethods, prefixRouteNameArg } from '@ember/routing/-internals';
import { ActionHandler } from '@ember/-internals/runtime';
import { symbol } from '@ember/-internals/utils';
import type Route from '@ember/routing/route';
import type Router from '@ember/routing/router';
import type { Transition } from 'router_js';

export type ControllerQueryParamType = 'boolean' | 'number' | 'array' | 'string';
Expand Down Expand Up @@ -302,33 +300,6 @@ const ControllerMixin = Mixin.create(ActionHandler, {
let value = get(controller, prop);
delegate(prop, value);
},

transitionToRoute<R extends Route>(...args: RouteArgs<R>): Transition {
deprecateTransitionMethods('controller', 'transitionToRoute');

// target may be either another controller or a router
let target = get(this, 'target');

// SAFETY: We can't actually assert that this is a full Controller or Router since some tests
// mock out an object that only has the single method. Since this is deprecated, I think it's
// ok to be a little less than proper here.
let method = (target as Controller).transitionToRoute ?? (target as Router<R>).transitionTo;

return method.apply(target, prefixRouteNameArg(this, args));
},

replaceRoute<R extends Route>(...args: RouteArgs<R>): Transition {
deprecateTransitionMethods('controller', 'replaceRoute');
// target may be either another controller or a router
let target = get(this, 'target');

// SAFETY: We can't actually assert that this is a full Controller or Router since some tests
// mock out an object that only has the single method. Since this is deprecated, I think it's
// ok to be a little less than proper here.
let method = (target as Controller).replaceRoute ?? (target as Router<R>).replaceWith;

return method.apply(target, prefixRouteNameArg(this, args));
},
});

// NOTE: This doesn't actually extend EmberObject.
Expand Down
2 changes: 1 addition & 1 deletion packages/@ember/routing/-internals.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { default as RouterState } from './lib/router_state';
export { default as RoutingService } from './lib/routing-service';
export { RouteArgs, deprecateTransitionMethods, prefixRouteNameArg } from './lib/utils';
export { RouteArgs, prefixRouteNameArg } from './lib/utils';
export {
default as generateController,
generateControllerFactory,
Expand Down
19 changes: 1 addition & 18 deletions packages/@ember/routing/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { get } from '@ember/-internals/metal';
import { getOwner } from '@ember/-internals/owner';
import type { ControllerQueryParam, ControllerQueryParamType } from '@ember/controller';
import { assert, deprecate } from '@ember/debug';
import { assert } from '@ember/debug';
import EngineInstance from '@ember/engine/instance';
import type { InternalRouteInfo, ModelFor } from 'router_js';
import type Router from 'router_js';
Expand Down Expand Up @@ -284,23 +284,6 @@ export function shallowEqual<A extends object, B extends object>(a: A, b: B): bo
return aCount === bCount;
}

export function deprecateTransitionMethods(frameworkClass: string, methodName: string): void {
deprecate(
`Calling ${methodName} on a ${frameworkClass} is deprecated. Use the RouterService instead.`,
false,
{
id: 'routing.transition-methods',
for: 'ember-source',
since: {
available: '3.26.0',
enabled: '3.26.0',
},
until: '5.0.0',
url: 'https://deprecations.emberjs.com/v3.x/#toc_routing-transition-methods',
}
);
}

function isRouteOptions(value: unknown): value is RouteOptions {
if (value && typeof value === 'object') {
let qps = (value as RouteOptions).queryParams;
Expand Down
Loading