|
| 1 | +- Start Date: 2018-19-12 |
| 2 | +- RFC PR: https://github.com/emberjs/rfcs/pull/421 |
| 3 | +- Ember Issue: (leave this empty) |
| 4 | + |
| 5 | +# Deprecate Application Controller Router Properties |
| 6 | + |
| 7 | +## Summary |
| 8 | + |
| 9 | +This RFC proposes the deprecation of `ApplicationController#currentPath` and `ApplicationController#currentRouteName`. |
| 10 | + |
| 11 | +## Motivation |
| 12 | + |
| 13 | +These APIs are no longer needed as the `RouterService` now has `RouterService#currentPath` and `RouterService#currentRouteName`. |
| 14 | +These fields are only ever present on the application controller which is a weird special casing that we would like to remove. |
| 15 | +Additionally, it's likely that there are very few if any consumers of this API as it is not documented. |
| 16 | + |
| 17 | +## Transition Path |
| 18 | + |
| 19 | +If you are reliant on `ApplicationController#currentPath` and `ApplicationController#currentRouteName` you can get the same functionality from the `RouterService` to migrate, inject the `RouterService` and read the `currentRouteName` or `currentPath` off of it. |
| 20 | + |
| 21 | +Before: |
| 22 | + |
| 23 | +```js |
| 24 | +// app/controllers/application.js |
| 25 | +import Controller from '@ember/controller'; |
| 26 | +import fetch from 'fetch'; |
| 27 | + |
| 28 | +export default Controller.extend({ |
| 29 | + store: service('store'), |
| 30 | + |
| 31 | + actions: { |
| 32 | + sendPayload() { |
| 33 | + fetch('/endpoint', { |
| 34 | + method: 'POST', |
| 35 | + body: JSON.stringify({ |
| 36 | + route: this.currentRouteName |
| 37 | + }) |
| 38 | + }); |
| 39 | + } |
| 40 | + } |
| 41 | +}) |
| 42 | +``` |
| 43 | + |
| 44 | +After: |
| 45 | + |
| 46 | +```js |
| 47 | +// app/controllers/application.js |
| 48 | +import Controller from '@ember/controller'; |
| 49 | +import fetch from 'fetch'; |
| 50 | + |
| 51 | +export default Controller.extend({ |
| 52 | + store: service('store'), |
| 53 | + router: service('router'), |
| 54 | + |
| 55 | + actions: { |
| 56 | + sendPayload() { |
| 57 | + fetch('/endpoint', { |
| 58 | + method: 'POST', |
| 59 | + body: JSON.stringify({ |
| 60 | + route: this.router.currentRouteName |
| 61 | + }) |
| 62 | + }); |
| 63 | + } |
| 64 | + } |
| 65 | +}) |
| 66 | +``` |
| 67 | + |
| 68 | +## How We Teach This |
| 69 | + |
| 70 | +There is likely very few consumers of this functionality and migration path is covered by existing documentation. |
| 71 | + |
| 72 | +## Drawbacks |
| 73 | + |
| 74 | +This may introduce churn that we are not aware of. |
| 75 | + |
| 76 | +## Alternatives |
| 77 | + |
| 78 | +No real alternative other than keep setting the properties. |
| 79 | + |
| 80 | +## Unresolved questions |
| 81 | + |
| 82 | +Optional, but suggested for first drafts. What parts of the design are still |
| 83 | +TBD? |
0 commit comments