Skip to content

Commit bd08ea3

Browse files
committed
Deprecate Observers
1 parent 7e57442 commit bd08ea3

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

text/1115-deprecate-observable.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
stage: accepted
3+
start-date: 2025-06-16T00: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: https://github.com/emberjs/rfcs/pull/1115
15+
project-link:
16+
---
17+
18+
# Deprecate Observers
19+
20+
## Summary
21+
22+
Deprecate the `Observable` Mixin, `observer` helper, and public observer functionality.
23+
24+
## Motivation
25+
26+
Using observers has been soft-deprecated ever since the introduction of tracking. Removing
27+
support for them will significantly clean up the code base. (Note that for us to entirely
28+
remove observer support internally, we will likely need to deprecate other functionality
29+
in addition to what is include here.)
30+
31+
Additionally, Ember has also not recommended the use of Mixins for a while. Since
32+
`Observable` uses the Mixin architecture, it will also need to be deprecated for us
33+
to fully remove Mixins.
34+
35+
## Transition Path
36+
37+
### Observable Mixin
38+
39+
Some of the methods provided by `Observable` are available as standalone methods,
40+
for these the transition path is straight-forward:
41+
42+
* `get` -> Import from `@ember/object`
43+
* `getProperties` -> Import from `@ember/object`
44+
* `set` -> Import from `@ember/object`
45+
* `setProperties` -> Import from `@ember/object`
46+
* `notifyPropertyChange` -> Import from `@ember/object`
47+
48+
For sugar helpers they can easily be replaced with a bit more verbosity:
49+
50+
* `incrementProperty`
51+
```js
52+
this.count += 1; // Tracking
53+
set(this, 'count', get(this, 'count') + 1); // Legacy
54+
```
55+
* `decrementProperty`
56+
```js
57+
this.count -= 1; // Tracking
58+
set(this, 'count', get(this, 'count') - 1); // Legacy
59+
```
60+
* `toggleProperty`
61+
```js
62+
this.flag = !this.flag; // Tracking
63+
set(this, 'flag', !get(this, 'flag')); // Legacy
64+
```
65+
66+
For others, there will no replacement and code that depends on them
67+
will have to be refactored:
68+
69+
* `addObserver`
70+
* `removeObserver`
71+
* `cacheFor`
72+
73+
### Observable Helper
74+
75+
This function does not work with native class syntax and as such, shouldn't be relied upon.
76+
It will not be replaced.
77+
78+
## Exploration
79+
80+
To validate this deprecation, I've tried removing this functionality in the following PRs:
81+
* Inline Observable Mixin: https://github.com/emberjs/ember.js/pull/20928
82+
* Remove `observer` helper: https://github.com/emberjs/ember.js/pull/20935
83+
* Remove inlined Observable methods: https://github.com/emberjs/ember.js/pull/20929 (Note this PR may change.)
84+
85+
## How We Teach This
86+
87+
We should remove all references to this functionality from the guides.
88+
89+
## Drawbacks
90+
91+
Many users probably rely on this functionality. However, it's almost certainly
92+
something that we don't want to support long-term.
93+
94+
## Alternatives
95+
96+
* Just inline this functionality so that we can at least get rid of Mixins.
97+
98+
## Unresolved questions
99+
100+
None

0 commit comments

Comments
 (0)