Skip to content

Commit

Permalink
Deprecate transition methods of controller and route
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeAstapov committed Apr 25, 2024
1 parent 3a4f719 commit 05c11a9
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions tests/dummy/app/templates/docs/deprecations.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,128 @@
# Deprecations

### § Transition methods of Controller and Route

**until**: 1.0.0

**id**: ember-engines.transition-methods

[RFC #674](https://github.com/emberjs/rfcs/pull/674) has deprecated the methods `transitionTo` and `replaceWith`
of the `Route` and the methods `transitionToRoute` and `replaceRoute` of `Controller`.
These methods have been removed in v5.0.0 of Ember.js, and developers encouraged to use `RouterService` instead.

The methods `transitionToExternal` and `replaceWithExternal` of the `Route` and the method `transitionToExternalRoute` of the `Controller`
share the same underlying code and follow the same spirit as ones deprecated in Ember.js.
Developers encouraged to use `EnginesRouterService` provided by [`ember-engines-router-service`](https://github.com/villander/ember-engines-router-service) instead.

Before:

```js
// my-engine/routes/foo.js
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class FooRoute extends Route {
@service session;

beforeModel() {
if (!this.session.isAuthenticated) {
this.transitionToExternal('login');
}
}
}
```

After:

```js
// my-engine/routes/foo.js
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class FooRoute extends Route {
@service router;
@service session;

beforeModel() {
if (!this.session.isAuthenticated) {
this.router.transitionToExternal('login');
}
}
}
```

Before:

```js
// my-engine/routes/foo.js
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class FooRoute extends Route {
@service session;

beforeModel() {
if (!this.session.isAuthenticated) {
this.replaceWithExternal('login');
}
}
}
```

After:

```js
// my-engine/routes/foo.js
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class FooRoute extends Route {
@service router;
@service session;

beforeModel() {
if (!this.session.isAuthenticated) {
this.router.replaceWithExternal('login');
}
}
}
```

Before:

```js
// my-engine/controllers/foo.js
import Controller from '@ember/controller';

export default class FooController extends Controller {
@action
async save({ title, text }) {
let post = this.store.createRecord('post', { title, text });
await post.save();
return this.transitionToExternalRoute('post', post.id);
}
}
```

After:

```js
// my-engine/controllers/foo.js
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class FooRoute extends Route {
@service router;

@action
async save({ title, text }) {
let post = this.store.createRecord('post', { title, text });
await post.save();
return this.router.transitionToExternal('post', post.id);
}
}
```

### § Use alias for inject router service from host application

**until**: 0.9.0
Expand Down

0 comments on commit 05c11a9

Please sign in to comment.