I would like my sessions to accept data changes from the server for existing records instead of ignoring them as is done currently.
The original did not apply new data, and there was some discussion about why. If I'm willing to lose user-edits is that the only issue with my approach?
Updating Session data on proxy load
Are there any other consequences of this override besides potentially losing user-edited data that has not been synced?
Code:
Ext.define('App.data.Session', {
extend: 'Ext.data.Session',
privates: {
recordCreator: function(data, Model) {
var me = this,
id = Model.getIdFromData(data),
record = me.peekRecord(Model, id, true);
if (!record) {
record = new Model(data, me);
} else {
record = me.getRecord(Model, id);
record.set(data, {
convert: false,
commit: true
});
}
return record;
}
}
});
The original did not apply new data, and there was some discussion about why. If I'm willing to lose user-edits is that the only issue with my approach?
Code:
recordCreator: function (data, Model) {
var me = this,
id = Model.getIdFromData(data),
record = me.peekRecord(Model, id, true);
// It doesn't exist anywhere, create it
if (!record) {
// We may have a stub that is loading the record (in fact this may be the
// call coming from that Reader), but the resolution is simple. By creating
// the record it is registered in the data[entityName][id] entry anyway
// and the stub will deal with it onLoad.
record = new Model(data, me);
} else {
//TODO no easy answer here... we are trying to create a record and have
//TODO some (potentially new) data. We probably should check for mid-air
//TODO collisions using versionProperty but for now we just ignore the
//TODO new data in favor of our potentially edited data.
// Peek checks if it exists at any level, by getting it we ensure that the record is copied down
record = me.getRecord(Model, id);
}
return record;
},
Updating Session data on proxy load
Aucun commentaire:
Enregistrer un commentaire