-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Ember Data background fetch RFC #61
Conversation
I thought about this some more last night and realized the RFC doesn't specify how a real time adapter would be able to signal to the store that it does not need to perform a background fetch. To solve this I think we would need to add 2 methods to the Adapter API. New Adapter MethodsThe first method This record would only be called if the record was already found in the store and is in the loaded state. {
/**
`shouldRefetchRecord` returns true if the adapter determines the record is
stale and should be refetch. It should return false if the record
is not stale or some other condition indicates that a fetch should
not happen at this time (e.g. loss of internet connection).
This method is synchronous.
@method shouldRefetchRecord
@param {DS.Store} store
@param {DS.Model} record
@param {Object} adapterOptions
@return {Boolean}
*/
shouldRefetchRecord: function(store, record, adapterOptions),
} The second method {
/**
`shouldBackgroundUpdate` returns true if the store should re fetch a
record in the store after returning it to the user to ensure the
record has the most up to date data.
This method is synchronous.
@method shouldBackgroundUpdate
@param {DS.Store} store
@param {DS.Model} record
@param {Object} adapterOptions
@return {Boolean}
*/
shouldBackgroundUpdate: function(store, record, adapterOptions),
} Store Find MethodsCurrently this rfc proposes using With the introduction of the new adapter methods mentioned above I think it would be possible for the background fetch behavior to happen in Piggy backing on some of the work done in RFC #27 I think public API for finding records in the store could look like this. {
/**
Use `peekById()` to retrieve a record by it's type and id if present in the
store. If there's no record matching the type and id `null` will be
returned.
This method is synchronous.
`getById` will be deprecated and renamed to `peekById`.
@method peekById
@param {String} type
@param {String} id
@return {DS.Model|null} record
*/
peekById: function(type, id),
/**
Use `peekAll()` to retrieve all records present in the store, by type.
This method is synchronous.
`all` will be deprecated and renamed to `peekAll`.
@method peekAll
@param {String} type
@return {DS.RecordArray} records
*/
peekAll: function(type),
/**
Use `findById()` to retrieve a record by it's type and id if present in the
store.
If the record is in the store the store will ask the adapter if the
record is stale. If the record is stale then the store will ask the
adapter to refetch the record. If the record is not stale then it
will resolve with the cached record immediately.
If there's no record matching the type and id the store will ask the
adapter to fetch the requested record.
This method is asynchronous.
`find(type, id)` will be deprecated and replaced by `findById`.
@method findById
@param {String} type
@param {String} id
@param {Object} adapterOptions
@return {DS.PromiseObject} record
*/
findById: function(type, id, adapterOptions),
/**
Use `findAll()` to retrieve all the records for a given type.
Before asking the adapter to find all the records the store will
first ask the adapter if the existing records it knows about are
stale. If they are stale then findAll will wait for the adapter to
find the records. Otherwise it will resolve immediately with all of
the known records in the store.
This method is asynchronous.
`find(type)` will be deprecated and replaced by `findAll`.
@method findAll
@param {String} type
@param {Object} adapterOptions
@return {DS.RecordArray} records
*/
findAll: function(type, adapterOptions),
/**
Use `fetchById()` to force the store to always fetch the latest
version of a record from the adapter.
This method is asynchronous.
@method fetch
@param {String} type
@param {String|Integer} id
@param {Object} adapterOptions
@return {DS.PromiseObject} record
*/
fetchById: function(type, id, adapterOptions),
/**
Use `fetchAll()` to force the store to always fetch all records
by type from the adapter.
This method is asynchronous.
@method findAll
@param {String} type
@param {Object} adapterOptions
@return {DS.RecordArray} records
*/
fetchAll: function(type, adapterOptions),
/**
Use `fetchQuery()` to ask the adapter to fetch all records by type
that match a query object. This method will always fetch new
records and never resolve with cached records from the store.
This method is asynchronous.
`findQuery(type, query)` will be deprecated and replaced by `fetchQuery`.
@method fetchQuery
@param {String} type
@param {Object} query
@param {Object} adapterOptions
@return {DS.RecordArray} records
*/
fetchQuery: function(type, query, adapterOptions),
/**
Use `fetchQueryOne()` to ask the adapter to fetch all records by type that match a query object and
it resolves with the first record returned.
This method is asynchronous.
@method fetchQueryOne
@param {String} type
@param {Object} query
@param {Object} adapterOptions
@return {DS.PromiseObject} record
*/
fetchQueryOne: function(type, query, adapterOptions),
} This results in a table that looks like this.
|
👍 |
I am not sure I am a huge fan of the name |
👍 |
Need to figure out what to do for |
There has been some talk of changing |
I second the fact that Anyway let's go with |
version and updates the record in-place if there are changes. | ||
|
||
|
||
In terms of the above methods `shouldRefetchRecord` will always return `false` and `shouldBackgroundUpdate` will always return `true` in the default `RESTAdapter`. |
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.
Maybe it's because I'm pretty used to ember-data current behaviour, but I think that return false from shouldBackgroundUpdate
would be a better default.
It is retrocompatible with what ED does now and I feel that refetch information that I already have is something you should opt-in to instead of opt-out.
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.
Some of the motivation for the background update to be true
by default is the belief that background updates provide a best of both worlds approach for new developers.
As for the retro-compatibility I agree with you there. The current thinking is for this feature will be introduces with shouldBackgroundUpdate
set to false
an a warning that the default will change in the next major version of Ember Data.
This is done and merged right? I think the ember data team should have access to manage their RFCs or at least get their own repo in ember-data/rfcs |
Yes, please close this if it's done. 👍 |
Merged and assigned in 10638ee. Thanks! |
Rendered