shouldReloadRecord (store, snapshot) Boolean
This method is used by the store to determine if the store should reload a record from the adapter when a record is requested by store.findRecord
.
If this method returns true
, the store will re-fetch a record from the adapter. If this method returns false
, the store will resolve immediately using the cached record.
For example, if you are building an events ticketing system, in which users can only reserve tickets for 20 minutes at a time, and want to ensure that in each route you have data that is no more than 20 minutes old you could write:
shouldReloadRecord: function(store, ticketSnapshot) { var timeDiff = moment().diff(ticketSnapshot.attr('lastAccessedAt'), 'minutes'); if (timeDiff > 20) { return true; } else { return false; } }
This method would ensure that whenever you do store.findRecord('ticket',
id)
you will always get a ticket that is no more than 20 minutes old. In case the cached version is more than 20 minutes old, findRecord
will not resolve until you fetched the latest version.
By default this hook returns false
, as most UIs should not block user interactions while waiting on data update.
Note that, with default settings, shouldBackgroundReloadRecord
will always re-fetch the records in the background even if shouldReloadRecord
returns false
. You can override shouldBackgroundReloadRecord
if this does not suit your use case.
Parameters:
-
store
DS.Store
-
snapshot
DS.Snapshot
Returns:
-
Boolean
Please login to continue.