-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CLEANUP] Refactor DataAdapter to not use observers or array observers #19379
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few inline comments, but we also need to change things around to avoid adding more than one backburner.on('end', ...)
callback as well as ensuring that we clean it up upon destruction. As it stands now, we leak in a few ways (registering the same callback many times, never removing but adding another callback per-container, etc).
packages/@ember/-internals/extension-support/lib/data_adapter.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/extension-support/lib/data_adapter.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/extension-support/lib/data_adapter.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/extension-support/lib/data_adapter.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/extension-support/lib/data_adapter.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/extension-support/lib/data_adapter.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/extension-support/lib/data_adapter.js
Outdated
Show resolved
Hide resolved
c8bf563
to
d2909c4
Compare
@@ -115,9 +115,9 @@ module.exports = { | |||
'cacheFor', | |||
'camelize', | |||
'canCatalogEntriesByType', | |||
'canInvoke', | |||
'cancel', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was partially sorted, but not fully. I decided to sort it to make it consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still doesn't seem to backburner.off('end', this.flushWatchers)
upon destruction (which means it leaks across multiple owners / tests).
packages/@ember/-internals/extension-support/lib/data_adapter.js
Outdated
Show resolved
Hide resolved
d2909c4
to
12b566a
Compare
The DataAdapter class is exposed specifically for the Ember Inspector to support Ember Data. Currently, the adapter relies on both array observers and standard observers. This PR refactors the adapter to use autotracking-based methods for tracking changes instead, with minimal API churn. The main change is to introduce a regular poll that checks for changes after each backburner runloop. There are two types of polling done: 1. `TypeWatcher`, which checks to see if a record array has changed at all (e.g. contents have changed) 2. `RecordsWatcher`, which watches the array as a whole _and_ the individual records within it. Whenever any changes occur, it reiterates the records array, and looks for new records, updated records, and removed records, and notifies of any changes. This removes the need for both array observers _and_ standard observers. Standard observers were previously used to detect changes on the model instances, but now we autotrack _serializing_ them, and that autotracking is used to detect if they've been updated. \## Breaking Changes - The `recordsRemoved` callback from `watchRecords` has changed. It now receives an array of removed records, _not_ an index and count. On the consuming side in Ember Inspector, we'll have to update the code to remove the items passed via id explicitly. - The `observeRecord` method has been removed. Because serializing the object _is_ observing it (via autotracking) there is no need to manually observe it. Users who are still implementing this method (e.g. Ember Data) can still keep it, and it shouldn't cause issues, it just will no longer be called.
12b566a
to
c43bd61
Compare
https://github.com/emberjs/data/pull/7435/files We have a minor test issue as a result of this refactor. Any ideas on how we can wait for the flush to happen? I see you are taking advantage of |
Correct, you should be able to use the |
Oh jeez. I was putting the |
The DataAdapter class is exposed specifically for the Ember Inspector to
support Ember Data. Currently, the adapter relies on both array
observers and standard observers. This PR refactors the adapter to use
autotracking-based methods for tracking changes instead, with minimal
API churn.
The main change is to introduce a regular poll that checks for changes
after each backburner runloop. There are two types of polling done:
TypeWatcher
, which checks to see if a record array has changed atall (e.g. contents have changed)
RecordsWatcher
, which watches the array as a whole and theindividual records within it. Whenever any changes occur, it
reiterates the records array, and looks for new records, updated
records, and removed records, and notifies of any changes.
This removes the need for both array observers and standard observers.
Standard observers were previously used to detect changes on the model
instances, but now we autotrack serializing them, and that
autotracking is used to detect if they've been updated.
## Breaking Changes
recordsRemoved
callback fromwatchRecords
has changed. It nowreceives an array of removed records, not an index and count. On the
consuming side in Ember Inspector, we'll have to update the code to
remove the items passed via id explicitly.
observeRecord
method has been removed. Because serializing theobject is observing it (via autotracking) there is no need to
manually observe it. Users who are still implementing this method
(e.g. Ember Data) can still keep it, and it shouldn't cause issues, it
just will no longer be called.