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
Copy file name to clipboardExpand all lines: content/ember/v6/deprecate-ember-object-observable.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,8 +87,7 @@ When working with legacy computed properties, the way you set matters for reacti
87
87
To trigger reactivity (like re-computing a dependent computed property) when changing a plain property, you **must** use the `set` function. A native JavaScript assignment (`person.firstName='Jane'`) will change the value but will **not** trigger reactivity.
88
88
89
89
```javascript
90
-
import { computed, set } from'@ember/object';
91
-
importEmberObjectfrom'@ember/object';
90
+
importEmberObject, { computed, set } from'@ember/object';
In contrast, if a computed property is defined with its own setter, you **can** use a native JavaScript assignment to update it. Ember will correctly intercept this and run your setter logic.
117
116
118
117
```javascript
119
-
import { computed } from'@ember/object';
120
-
importEmberObjectfrom'@ember/object';
118
+
importEmberObject, { computed, set } from'@ember/object';
Copy file name to clipboardExpand all lines: content/ember/v6/deprecate-ember-object-observers.md
+100Lines changed: 100 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -210,4 +210,104 @@ This approach is much cleaner because:
210
210
2. It clearly separates the component's data and template from the DOM-specific logic.
211
211
3. The modifier's lifecycle (setup, update, teardown) is managed by Ember, making it more robust.
212
212
213
+
### Replacing Observer-Based Waiting Patterns
213
214
215
+
Sometimes observers were used not just to mirror state into another property or invoke a side effect immediately, but to "wait" until a property reached a certain condition (e.g. became non-null / a flag flipped) and then continue logic. Instead of wiring an observer that removes itself when the predicate passes, choose one of these approaches:
216
+
217
+
#### 1. Prefer Reactive Rendering (Often You Need Nothing Extra)
218
+
219
+
If the goal is just to show different UI when something becomes ready, branch in the template:
220
+
221
+
```hbs
222
+
{{#if this.isReady}}
223
+
<LoadedState @data={{this.data}} />
224
+
{{else}}
225
+
<LoadingSpinner />
226
+
{{/if}}
227
+
```
228
+
229
+
`this.isReady` should be a `@tracked` property (or derived from other tracked state). No explicit watcher is required; changes trigger re-render automatically.
0 commit comments