Closed
Description
Usecase: server pushes updates to already loaded records. In order to save bandwidth, the server pushes only changed attributes and not the whole record. As a result, we end up with the record with a lot of missing attributes.
As a work-around, I've implemented this:
App.Store = DS.Store.extend({
load: function (type, id, hash) {
var id = id+'',
typeMap = this.typeMapFor(type),
clientId = typeMap.idToCid[id],
currentHash, resultHash;
if (clientId) {
var record = this.recordCache[clientId];
if (record) {
// record is materialized and data is processed
currentHash = this.getDataOfMaterializedRecord(record);
} else {
// record is not materialized yet, its hash is cached
currentHash = this.clientIdToHash[clientId];
}
resultHash = $.extend({}, currentHash, hash);
} else {
resultHash = hash;
}
this._super(type, id, resultHash);
},
getDataOfMaterializedRecord: function (record) {
var data = record.get("data");
return $.extend({}, data.attributes, data.belongsTo, data.hasMany);
},
});