|
| 1 | +--- |
| 2 | +stage: accepted |
| 3 | +start-date: 2025-06-13T00:00:00.000Z |
| 4 | +release-date: |
| 5 | +release-versions: |
| 6 | +teams: # delete teams that aren't relevant |
| 7 | + - cli |
| 8 | + - data |
| 9 | + - framework |
| 10 | + - learning |
| 11 | + - steering |
| 12 | + - typescript |
| 13 | +prs: |
| 14 | + accepted: # update this to the PR that you propose your RFC in |
| 15 | +project-link: |
| 16 | +--- |
| 17 | + |
| 18 | +<!--- |
| 19 | +Directions for above: |
| 20 | +
|
| 21 | +stage: Leave as is |
| 22 | +start-date: Fill in with today's date, 2032-12-01T00:00:00.000Z |
| 23 | +release-date: Leave as is |
| 24 | +release-versions: Leave as is |
| 25 | +teams: Include only the [team(s)](README.md#relevant-teams) for which this RFC applies |
| 26 | +prs: |
| 27 | + accepted: Fill this in with the URL for the Proposal RFC PR |
| 28 | +project-link: Leave as is |
| 29 | +--> |
| 30 | + |
| 31 | +# Deprecating the `Evented` Mixin |
| 32 | + |
| 33 | +## Summary |
| 34 | + |
| 35 | +Deprecate the `Evented` Mixin in favor of just using the methods from `@ember/object/events`. |
| 36 | + |
| 37 | +## Motivation |
| 38 | + |
| 39 | +For a while now, Ember has not recommended the use of Mixins. In order to fully |
| 40 | +deprecate Mixins, we need to deprecate all existing Mixins of which `Evented` is one. |
| 41 | + |
| 42 | +## Transition Path |
| 43 | + |
| 44 | +The `Evented` Mixin provides the following methods: `on`, `one`, `off`, `trigger`, and `has`. |
| 45 | + |
| 46 | +Of these all but `has` are just wrapping methods provided by `@ember/object/events` and |
| 47 | +migration is straight-forward: |
| 48 | + |
| 49 | +* `obj.on(name, target, method?)` -> `addListener(obj, name, target, method)` |
| 50 | +* `obj.one(name, target, method?)` -> `addListener(obj, name, target, method, true)` |
| 51 | +* `obj.trigger(name, ...args)` -> `sendEvent(obj, name, args)` |
| 52 | +* `obj.off(name, target, method?)` -> `removeListener(obj, name, target, method)` |
| 53 | + |
| 54 | +Unfortunately, `hasListeners` is not directly exposed by `@ember/object/events`. |
| 55 | +We should consider exposing it as the others. In this case, the transition would be: |
| 56 | + |
| 57 | +* `obj.has(name)` -> `hasListeners(obj, name)` |
| 58 | + |
| 59 | +## How We Teach This |
| 60 | + |
| 61 | +In general, I think we should discourage the use of Evented and event handlers as |
| 62 | +a core Ember feature and remove most references from the guids. |
| 63 | + |
| 64 | +## Drawbacks |
| 65 | + |
| 66 | +Many users probably rely on this functionality. However, it's almost certainly |
| 67 | +something that we don't need to keep in Ember itself. |
| 68 | + |
| 69 | +## Alternatives |
| 70 | + |
| 71 | +* Convert `Evented` to a class decorator-style mixin. |
| 72 | + |
| 73 | +## Unresolved questions |
| 74 | + |
| 75 | +Should we inline the functionality of `Evented` into the classes that use it or are |
| 76 | +we also deprecating the methods on those classes? |
0 commit comments