Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1921 from vogdb/issue-1921
Browse files Browse the repository at this point in the history
Pass context of caller to promiseThrottler.
  • Loading branch information
vogdb committed Oct 8, 2015
2 parents 383c502 + 64a55fd commit 4941286
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@
}
if (options.queue && promise && promise.isPending()) {
var args = arguments;
var self = this;
promise = promise.then(function() {
return fn.apply(null, args);
return fn.apply(self, args);
}).catch(function() {
return fn.apply(null, args);
return fn.apply(self, args);
});
}
if (!promise || !promise.isPending()) {
promise = fn.apply(null, arguments);
promise = fn.apply(this, arguments);
}
return promise;
};
Expand Down
70 changes: 32 additions & 38 deletions library/CM/Layout/Abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,42 @@ var CM_Layout_Abstract = CM_View_Abstract.extend({
_$pagePlaceholder: null,

/** @type PromiseThrottled|Null */
_loadPageThrottled: null,
_loadPageThrottled: promiseThrottler(function(path) {
var layout = this;
layout._chargeSpinnerTimeout();

return this.ajaxModal('loadPage', {path: path})
.then(function(response) {
layout._clearSpinnerTimeout();
if (response.redirectExternal) {
cm.router.route(response.redirectExternal);
return;
}
var view = layout._injectView(response);
var reload = (layout.getClass() != response.layoutClass);
if (reload) {
window.location.replace(response.url);
return;
}
layout._removePagePlaceholder(view.$el);
layout._updateHistory(path, response.url);
layout._onPageSetup(response.title, response.menuEntryHashList, response.jsTracking);
view._ready();
return view;
})
.catch(function(error) {
layout._clearSpinnerTimeout();
if (!(error instanceof Promise.CancellationError)) {
layout._errorPagePlaceholder(error);
layout._onPageError();
throw error;
}
});
}, {cancelLeading: true}),

/** @type {Number} timeout ID */
_timeoutLoading: null,

initialize: function() {
CM_View_Abstract.prototype.initialize.call(this);

var layout = this;
this._loadPageThrottled = promiseThrottler(function(path) {
layout._chargeSpinnerTimeout();

return layout.ajaxModal('loadPage', {path: path})
.then(function(response) {
layout._clearSpinnerTimeout();
if (response.redirectExternal) {
cm.router.route(response.redirectExternal);
return;
}
var view = layout._injectView(response);
var reload = (layout.getClass() != response.layoutClass);
if (reload) {
window.location.replace(response.url);
return;
}
layout._removePagePlaceholder(view.$el);
layout._updateHistory(path, response.url);
layout._onPageSetup(response.title, response.menuEntryHashList, response.jsTracking);
view._ready();
return view;
})
.catch(function(error) {
layout._clearSpinnerTimeout();
if (!(error instanceof Promise.CancellationError)) {
layout._errorPagePlaceholder(error);
layout._onPageError();
throw error;
}
});
}, {cancelLeading: true});
},

/**
* @returns {CM_View_Abstract|null}
*/
Expand Down

0 comments on commit 4941286

Please sign in to comment.