PDA

View Full Version : [FIXED] [4.2.1] Store callback called with different aruments



anton.dimitrov
9 Apr 2013, 4:20 AM
Ext version tested:

Ext 4.2.1 (4.2.1.740)

Browser versions tested against:

FF

Description:

The callback function of store.load() is called with different arguments when using infinite store
If you look at the function Ext.data.Store.loadToPrefetch()

loadToPrefetch: function(options) {
var me = this,
i,
records,
dataSetSize,
prefetchOptions = options,

// Get the requested record index range in the dataset
startIdx = options.start,
endIdx = options.start + options.limit - 1,

// The end index to load into the store's live record collection
loadEndIdx = Math.min(endIdx, options.start + (me.viewSize || options.limit) - 1),

// Calculate a page range which encompasses the requested range plus both buffer zones.
// The endPage will be adjusted to be in the dataset size range as soon as the first data block returns.
startPage = me.getPageFromRecordIndex(Math.max(startIdx - me.trailingBufferZone, 0)),
endPage = me.getPageFromRecordIndex(endIdx + me.leadingBufferZone),

// Wait for the viewable range to be available
waitForRequestedRange = function() {
if (me.rangeCached(startIdx, loadEndIdx)) {
me.loading = false;
records = me.data.getRange(startIdx, loadEndIdx);
me.data.un('pageAdded', waitForRequestedRange);

// If there is a listener for guranteedrange then fire that event
if (me.hasListeners.guaranteedrange) {
me.guaranteeRange(startIdx, loadEndIdx, options.callback, options.scope);
}
if (options.callback) {
options.callback.call(options.scope||me, records, startIdx, endIdx, options);
}
me.fireEvent('datachanged', me);
me.fireEvent('refresh', me);
me.fireEvent('load', me, records, true);
if (options.groupChange) {
me.fireGroupChange();
}
}
};

if (me.fireEvent('beforeload', me, options) !== false) {

// So that prefetchPage does not consider the store to be fully loaded if the local count is equal to the total count
delete me.totalCount;

me.loading = true;

// Any configured callback is handled in waitForRequestedRange above.
// It should not be processed by onProxyPrefetch.
if (options.callback) {
prefetchOptions = Ext.apply({}, options);
delete prefetchOptions.callback;
}

// Load the first page in the range, which will give us the initial total count.
// Once it is loaded, go ahead and prefetch any subsequent pages, if necessary.
// The prefetchPage has a check to prevent us loading more than the totalCount,
// so we don't want to blindly load up <n> pages where it isn't required.
me.on('prefetch', function(store, records, successful, operation) {

if (successful) {
// If there is data in the dataset, we can go ahead and add the pageAdded listener which waits for the visible range
// and we can also issue the requests to fill the surrounding buffer zones.
if ((dataSetSize = me.getTotalCount())) {

// Wait for the requested range to become available in the page map
me.data.on('pageAdded', waitForRequestedRange);

// As soon as we have the size of the dataset, ensure we are not waiting for more than can ever arrive,
loadEndIdx = Math.min(loadEndIdx, dataSetSize - 1);

// And make sure we never ask for pages beyond the end of the dataset.
endPage = me.getPageFromRecordIndex(Math.min(loadEndIdx + me.leadingBufferZone, dataSetSize - 1));

for (i = startPage + 1; i <= endPage; ++i) {
me.prefetchPage(i, prefetchOptions);
}
} else {
me.fireEvent('datachanged', me);
me.fireEvent('refresh', me);
me.fireEvent('load', me, records, true);
}
}
// Unsuccessful prefetch: fire a load event with success false.
else {
me.fireEvent('load', me, records, false);
}
}, null, {single: true});

me.prefetchPage(startPage, prefetchOptions);
}
},
You will see that
waitForRequestedRange = function() {
if (me.rangeCached(startIdx, loadEndIdx)) {
me.loading = false;
records = me.data.getRange(startIdx, loadEndIdx);
me.data.un('pageAdded', waitForRequestedRange);

// If there is a listener for guranteedrange then fire that event
if (me.hasListeners.guaranteedrange) {
me.guaranteeRange(startIdx, loadEndIdx, options.callback, options.scope);
}
if (options.callback) {
options.callback.call(options.scope||me, records, startIdx, endIdx, options);
}
me.fireEvent('datachanged', me);
me.fireEvent('refresh', me);
me.fireEvent('load', me, records, true);
if (options.groupChange) {
me.fireGroupChange();
}
}
};

How to reproduce:


Check http://localhost/ext-4.2.1/examples/grid/infinite-scroll-with-filter.html
and use grid.getStore().load({callback:function (){console.log(arguments)}})
43015



Operating System:


Win7

slemmon
9 Apr 2013, 7:40 AM
Thanks for the report! I have opened a bug in our bug tracker.

anton.dimitrov
9 Apr 2013, 8:27 AM
Do you have any suggestions for a quick fix? Also do you think this will make it for 4.2.1 ?

Anton
10x

anton.dimitrov
27 May 2013, 1:21 AM
Can anybody tell me the status of this bug?