PDA

View Full Version : [CLOSED-1117] Ext.data.DataReader bug when running with minimal build



Munter
13 Jul 2010, 6:46 AM
I am running an appliaction with a minimal build, which means I have stripped away XmlReader because I am only using JsonReader.

Now, when the DataReader superclass extracts data it checks if it is an instance of either JsonReader or XmlReader. Apart from the weird architecture here, which the comments clearly show are on a todo-list to be fixed, this gives me another problem.

Calling instanceof on an undefined property fails. I suggest testing if the two constructors exist before checking if DataReader is an instance of them.


Ext.override(Ext.data.DataReader, {
/**
* returns extracted, type-cast rows of data. Iterates to call #extractValues for each row
* @param {Object[]/Object} data-root from server response
* @param {Boolean} returnRecords [false] Set true to return instances of Ext.data.Record
* @private
*/
extractData : function(root, returnRecords) {
// A bit ugly this, too bad the Record's raw data couldn't be saved in a common property named "raw" or something.
var rawName = (Ext.isDefined(Ext.data.JsonReader) && this instanceof Ext.data.JsonReader) ? 'json' : 'node';

var rs = [];

// Had to add Check for XmlReader, #isData returns true if root is an Xml-object. Want to check in order to re-factor
// #extractData into DataReader base, since the implementations are almost identical for JsonReader, XmlReader
if (this.isData(root) && !(Ext.isDefined(Ext.data.XmlReader) && this instanceof Ext.data.XmlReader)) {
root = [root];
}
var f = this.recordType.prototype.fields,
fi = f.items,
fl = f.length/*,
rs = []*/;
if (returnRecords === true) {
var Record = this.recordType;
for (var i = 0; i < root.length; i++) {
var n = root[i];
var record = new Record(this.extractValues(n, fi, fl), this.getId(n));
record[rawName] = n; // <-- There's implementation of ugly bit, setting the raw record-data.
rs.push(record);
}
}
else {
for (var i = 0; i < root.length; i++) {
var data = this.extractValues(root[i], fi, fl);
data[this.meta.idProperty] = this.getId(root[i]);
rs.push(data);
}
}
return rs;
}
});

edspencer
13 Jul 2010, 1:37 PM
Too much would need to change to fix this in 3.x. It is already addressed in 4.x's new data package.