You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deprecate the `Evented`Mixin in favor of just using the methods from `@ember/object/events`.
35
+
Deprecate the `Ember.Evented`mixin, the underlying `@ember/object/events` module (`addListener`, `removeListener`, `sendEvent`), and the `on()` function from `@ember/object/evented`.
36
36
37
37
## Motivation
38
38
39
39
For a while now, Ember has not recommended the use of Mixins. In order to fully
40
40
deprecate Mixins, we need to deprecate all existing Mixins of which `Evented` is one.
41
41
42
+
Further, the low-level event system in `@ember/object/events` predates modern
43
+
JavaScript features (classes, modules, native event targets, async / await) and
44
+
encourages an ad-hoc, implicit communication style that is difficult to statically
45
+
analyze and can obscure data flow. Removing it simplifies Ember's object model and
46
+
reduces surface area. Applications have many well-supported alternatives for
47
+
cross-object communication (services with explicit APIs, tracked state, resources,
48
+
native DOM events, AbortController-based signaling, promise-based libraries, etc.).
49
+
42
50
## Transition Path
43
51
44
-
The `Evented` Mixin provides the following methods: `on`, `one`, `off`, `trigger`, and `has`.
52
+
The following are deprecated:
53
+
54
+
* The `Ember.Evented` mixin
55
+
* The functions exported from `@ember/object/events` (`addListener`, `removeListener`, `sendEvent`)
56
+
* The `on()` function exported from `@ember/object/evented`
57
+
* Usage of the `Evented` methods (`on`, `one`, `off`, `trigger`, `has`) when mixed into framework classes (`Ember.Component`, `Ember.Route`, `Ember.Router`)
58
+
59
+
Exception: The methods will continue to be supported (not deprecated) on the `RouterService`, since key parts of its functionality are difficult to reproduce without them. This RFC does not propose deprecating those usages.
60
+
61
+
### Recommended Replacement Pattern
62
+
63
+
Rather than mixing in a generic event emitter, we recommend refactoring affected code so that:
64
+
65
+
1. A service (or other long‑lived owner-managed object) exposes explicit subscription methods (e.g. `onLoggedIn(cb)`), and
66
+
2. Internally uses a small event emitter implementation. We recommend the modern promise‑based [emittery](https://www.npmjs.com/package/emittery) library, though any equivalent (including a minimal custom implementation) is acceptable.
67
+
68
+
This yields clearer public APIs, encapsulates implementation details, and makes teardown explicit by returning an unsubscribe function that can be registered with `registerDestructor`.
Libraries like `emittery` provide asynchronous (promise‑based) event emission by default. Code which previously depended on synchronous delivery ordering may need to be updated. If strict synchronous behavior is required, a synchronous emitter (custom or another library) can be substituted without changing the public API shape shown above.
58
176
59
177
## Exploration
60
178
61
-
To validate this deprecation, I've tried removing the `Evented` Mixin from Ember.js in this PR:
62
-
https://github.com/emberjs/ember.js/pull/20917
179
+
To validate this deprecation, we explored removal of the `Evented` mixin from Ember.js core (see: https://github.com/emberjs/ember.js/pull/20917) and confirmed that its usage is largely isolated and can be shimmed or refactored at the application layer.
63
180
64
181
## How We Teach This
65
182
66
-
In general, I think we should discourage the use of Evented and event handlers as
67
-
a core Ember feature and remove most references from the guids.
183
+
* Update the deprecations guide (see corresponding PR in the deprecation app) with the migration example above.
184
+
* Remove most references to `Evented` from the Guides, replacing ad-hoc event usage examples with explicit service APIs.
185
+
* Emphasize explicit state and method calls, tracked state, resources, and native DOM events for orchestration.
68
186
69
187
## Drawbacks
70
188
71
-
Many users probably rely on this functionality. However, it's almost certainly
72
-
something that we don't need to keep in Ember itself.
189
+
* Applications relying heavily on synchronous event ordering may require careful refactors; asynchronous emitters change timing.
190
+
* Some addons may still expose `Evented`-based APIs and will need releases.
191
+
* Introduces a (small) external dependency when adopting an emitter library—though apps can implement a minimal sync emitter inline if desired.
73
192
74
193
## Alternatives
75
194
76
-
* Convert `Evented` to a class decorator-style mixin.
195
+
* Convert `Evented` to a decorator-style mixin (retains implicit pattern, less desirable).
196
+
* Keep `@ember/object/events` but deprecate only the mixin (adds partial complexity, limited long‑term value).
197
+
* Replace with a built-in minimal emitter utility instead of recommending third‑party (adds maintenance burden for Ember core).
77
198
78
-
## Unresolved questions
199
+
## Unresolved Questions
79
200
80
-
Should we inline the functionality of `Evented` into the classes that use it or are
81
-
we also deprecating the methods on those classes?
201
+
* Do we want to provide (or document) a canonical synchronous emitter alternative for cases where timing matters?
202
+
* Should we explicitly codemod support (e.g. generate service wrapper methods) or leave migration manual?
203
+
* Any additional framework internals still relying on these APIs that require staged removal?
0 commit comments