Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store fixes #411

Merged
4 commits merged into from
Feb 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions OnDemandList.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ return declare([List, _StoreMixin], {
// Used as errback for when calls;
// remove the loadingNode and re-throw if an error was passed
put(loadingNode, "!");
if(err){ throw err; }

if(err){
if(self._refreshDeferred){
self._refreshDeferred.reject(err);
delete self._refreshDeferred;
}
throw err;
}
}

// Establish query options, mixing in our own.
Expand Down Expand Up @@ -190,7 +197,7 @@ return declare([List, _StoreMixin], {
// resolve it now (_processScroll will remove it and resolve it itself
// otherwise)
if(self._refreshDeferred){
self._refreshDeferred.resolve({ results: results, rows: trs });
self._refreshDeferred.resolve(results);
delete self._refreshDeferred;
}

Expand Down Expand Up @@ -238,24 +245,23 @@ return declare([List, _StoreMixin], {
// containing `results` (QueryResults) and `rows` (the rendered rows);
// externally the promise will resolve simply with the QueryResults, but
// the event will be emitted with both under respective properties.
return dfd.then(function(obj){
return dfd.then(function(results){
// Emit on a separate turn to enable event to be used consistently for
// initial render, regardless of whether the backing store is async
setTimeout(function() {
listen.emit(self.domNode, "dgrid-refresh-complete", {
bubbles: true,
cancelable: false,
grid: self,
results: obj.results, // QueryResults object (may be a wrapped promise)
rows: obj.rows // array of rendered row elements
results: results // QueryResults object (may be a wrapped promise)
});
}, 0);

// Delete the Deferred immediately so nothing tries to re-resolve
delete self._refreshDeferred;

// Resolve externally with just the QueryResults
return obj.results;
return results;
}, function(err){
delete self._refreshDeferred;
throw err;
Expand Down Expand Up @@ -533,8 +539,8 @@ return declare([List, _StoreMixin], {
// resolve the refresh promise based on the latest results obtained
if (lastRows && (refreshDfd = this._refreshDeferred)) {
delete this._refreshDeferred;
Deferred.when(lastRows, function(rows) {
refreshDfd.resolve({ results: lastResults, rows: rows });
Deferred.when(lastRows, function() {
refreshDfd.resolve(lastResults);
});
}
}
Expand Down
6 changes: 5 additions & 1 deletion _StoreMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ function(kernel, declare, lang, Deferred, listen, put){
// This module isolates the base logic required by store-aware list/grid
// components, e.g. OnDemandList/Grid and the Pagination extension.

// Noop function, needed for _trackError when callback due to a bug in 1.8
// (see http://bugs.dojotoolkit.org/ticket/16667)
function noop(value){ return value; }

function emitError(err){
// called by _trackError in context of list/grid, if an error is encountered
if(typeof err !== "object"){
Expand Down Expand Up @@ -264,7 +268,7 @@ function(kernel, declare, lang, Deferred, listen, put){
}

// wrap in when call to handle reporting of potential async error
return Deferred.when(result, null, lang.hitch(this, emitError));
return Deferred.when(result, noop, lang.hitch(this, emitError));
},

newRow: function(){
Expand Down
17 changes: 16 additions & 1 deletion extensions/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ function(_StoreMixin, declare, lang, Deferred, on, query, string, has, put, i18n
},

refresh: function(){
var self = this;

this.inherited(arguments);

if(!this.store){
Expand All @@ -246,7 +248,20 @@ function(_StoreMixin, declare, lang, Deferred, on, query, string, has, put, i18n
}

// Reset to first page and return promise from gotoPage
return this.gotoPage(1);
return this.gotoPage(1).then(function(results){
// Emit on a separate turn to enable event to be used consistently for
// initial render, regardless of whether the backing store is async
setTimeout(function() {
on.emit(self.domNode, "dgrid-refresh-complete", {
bubbles: true,
cancelable: false,
grid: self,
results: results // QueryResults object (may be a wrapped promise)
});
}, 0);

return results;
});
},

_onNotification: function(rows){
Expand Down
2 changes: 1 addition & 1 deletion test/performance.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
};

grid.on("dgrid-refresh-complete", function(evt) {
console.log("Refresh completed ", evt.results, evt.rows);
console.log("Refresh completed ", evt.results);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/performance_slow_network.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
console.log(new Date().getTime() - start);

grid.on("dgrid-refresh-complete", function(evt) {
console.log("Refresh completed", evt.results, evt.rows);
console.log("Refresh completed", evt.results);
});
});

Expand Down