Skip to content

Commit

Permalink
Updated base on emberjs/data#8807
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltazore committed Aug 30, 2023
1 parent 3c45097 commit 551570e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ displayId: <none yet assigned>

This is a planned deprecation which will trigger when observer or computed chains are used to watch for changes on any EmberData RecordArray, ManyArray or PromiseManyArray.

Support for these chains is currently guarded by the inactive deprecation flag listed here.
Support for these chains is currently guarded by the deprecation flag listed here, enabling removal of the behavior if desired.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Deprecate Legacy Imports
until: '6.0'
since: '5.2'
since: '5.3'
displayId: ember-data:deprecate-legacy-imports
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Deprecate Non Strict Id
until: '6.0'
since: '5.2'
since: '5.3'
displayId: ember-data:deprecate-non-strict-id
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Deprecate Non Strict Types
until: '6.0'
since: '5.2'
since: '5.3'
displayId: ember-data:deprecate-non-strict-types
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Deprecate Non Strict Types
title: Deprecate Non Uniq Payloads
until: '6.0'
since: '5.2'
since: '5.3'
displayId: ember-data:deprecate-non-unique-collection-payloads
---

Deprecates when the data for a hasMany relationship contains duplicate identifiers.
Deprecates when the data for a `hasMany` relationship contains duplicate identifiers.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: Deprecate Non Uniq Payloads
until: '6.0'
since: '5.3'
displayId: ember-data:deprecate-relationship-remote-update-clearing-local-state
---

Deprecates when a relationship is updated remotely and the local state is cleared of all changes except for "new" records.

Instead, any records not present in the new payload will be considered "removed" while any records present in the new payload will be considered "added".

This allows us to "commit" local additions and removals, preserving any additions or removals that are not yet reflected in the remote state.

For instance, given the following initial state:

```plaintext
remote: A, B, C
local: add D, E
remove B, C
=> A, D, E
```

If after an update, the remote state is now A, B, D, F then the new state will be

```plaintext
remote: A, B, D, F
local: add E
remove B
=> A, D, E, F
```

Under the old behavior the updated local state would instead have been

```plaintext
=> A, B, D, F
```

Similarly, if a belongsTo remote State was A while its local state was B, then under the old behavior if the remote state changed to C, the local state would be updated to C. Under the new behavior, the local state would remain B.

If the remote state was A while its local state was `null`, then under the old behavior if the remote state changed to C, the local state would be updated to C. Under the new behavior, the local state would remain `null`.

Thus the new correct mental model is that the state of the relationship at any point in time is whatever the most recent remote state is, plus any local additions or removals you have made that have not yet been reflected by the remote state.

> Note: The old behavior extended to modifying the inverse of a relationship. So if you had local state not reflected in the new remote state, inverses would be notified and their state reverted as well when "resetting" the relationship. Under the new behavior, since the local state is preserved the inverses will also not be reverted.
### Resolving this deprecation

Resolving this deprecation can be done individually for each relationship or globally for all relationships.

To resolve it globally, set the `DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE` to `false` in ember-cli-build.js

```js
let app = new EmberApp(defaults, {
emberData: {
deprecations: {
// set to false to strip the deprecated code (thereby opting into the new behavior)
DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE: false
}
}
})
```

To resolve this deprecation on an individual relationship, adjust the `options` passed to the relationship. For relationships with inverses, both sides MUST be migrated to the new behavior at the same time.

```js
class Person extends Model {
@hasMany('person', {
async: false,
inverse: null,
resetOnRemoteUpdate: false
}) children;
*
@belongsTo('person', {
async: false,
inverse: null,
resetOnRemoteUpdate: false
}) parent;
}
```

> Note: false is the only valid value here, all other values (including missing) will be treated as true, where `true` is the legacy behavior that is now deprecated.
Once you have migrated all relationships, you can remove the the resetOnRemoteUpdate option and set the deprecation flag to false in ember-cli-build.

0 comments on commit 551570e

Please sign in to comment.