PDA

View Full Version : Equivalent of Ext.data.reader.Reader.readRecords when creating Model directly?



JamieMason
17 Oct 2011, 2:04 AM
I'm in a sorry position where I have to transform the data I'm getting so it's workable, I've overridden Ext.data.reader.Reader.readRecords to do this when the data comes in from the Server.

I'm writing unit tests for this code at the moment and in those I'm using Ext.create to instantiate my test stubs. When calling Ext.create though, the Ext.data.reader.* isn't involved.

Is there an equivalent method which transforms the data passed to Ext.create?


Ext.define('SomeModel', { extend: 'Ext.data.Model'
, proxy: {
type: 'ajax'
, url: 'http://etc'
, reader: {
type: 'json'
, readRecords: function (suckyJson)
{
var somethingICanUse = [];

// Herd cats

return new Ext.data.ResultSet({
records: somethingICanUse
, success: true
, total: somethingICanUse.length
, count: somethingICanUse.length
});
}
}
}
, fields: [
// my fields
]
});

Thanks.

skirtle
17 Oct 2011, 4:34 AM
This thread is vaguely related:

http://www.sencha.com/forum/showthread.php?144756

Thought occurs that for testing the reader you could try using a memory proxy:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Memory

That said, I don't really understand why you'd need to use the real reader and fake models in the same unit test. Seems a bit odd to me.

JamieMason
12 Dec 2011, 1:40 AM
Thanks again Skirtle