PDA

View Full Version : Operation resultSet vs. records



aflx
29 Jan 2012, 1:42 AM
Hi,

can anyone please explain the differences between Operation.resultSet and Operation.records!?
Since PR4 it seems that a proxy has to set both on success, in PR3 only resultSet was set.

For example WebStorage.read():

PR3:



...
operation.setCompleted();

operation.resultSet = Ext.create('Ext.data.ResultSet', {
records: records,
total : records.length,
loaded : true
});

if (typeof callback == 'function') {
callback.call(scope || this, operation);
}
...


PR4:



...
operation.setCompleted();

operation.setResultSet(Ext.create('Ext.data.ResultSet', {
records: records,
total : records.length,
loaded : true
}));
operation.setRecords(records);

if (typeof callback == 'function') {
callback.call(scope || this, operation);
}
...


What is it good for to set records, it is already set in the resultSet!?

Thanks!
Alex

TommyMaintz
29 Jan 2012, 8:12 AM
The reason this looks a bit funny in WebStorage is because it is trying to create the exact same result as a Server proxy.

One of the bigger changes in the data package is that when a proxy processes a response from the server, it calls reader.process() passing the response. The reader reads out the data and returns a ResultSet with the data in the "records" config. We then call operation.process() passing this ResultSet. The operation will handle each type of action (read, update, create, destroy), and then calls this.setRecords() after it is done processing. We then pass the Operation to the callback.

All this means is that in the callback, the way you have to get the record instances is to call operation.getRecords(). Again, the reason this all looks a bit funny in the WebStorage proxy is because when we get data from LocalStorage, we don't have the reader actually process this ResultSet.

In the old data package reader.read() was called which actually returned Model instances. We then had code spread out everywhere that would merge and commit these new record instances with the old ones, which often actually didn't work at all.

Sorry if my explanation is a bit hard to understand. Let me know if you have any more questions about this.