Skip to content

Commit

Permalink
make preloadPage method return Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrchk committed Feb 3, 2019
1 parent a7a595f commit 33367a1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
35 changes: 20 additions & 15 deletions dist/swup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1559,22 +1559,27 @@ module.exports = function (pathname) {

var link = new _Link2.default();
link.setPath(pathname);
if (link.getAddress() != this.currentUrl && !this.cache.exists(link.getAddress()) && this.preloadPromise == null) {
this.getPage({ url: link.getAddress() }, function (response, request) {
if (request.status === 500) {
_this.triggerEvent('serverError');
return;
} else {
// get json data
var page = _this.getDataFromHtml(response, request);
if (page != null) {
page.url = link.getAddress();
_this.cache.cacheUrl(page, _this.options.debugMode);
_this.triggerEvent('pagePreloaded');
return new Promise(function (resolve, reject) {
if (link.getAddress() != _this.currentUrl && !_this.cache.exists(link.getAddress())) {
_this.getPage({ url: link.getAddress() }, function (response, request) {
if (request.status === 500) {
_this.triggerEvent('serverError');
reject();
} else {
// get json data
var page = _this.getDataFromHtml(response, request);
if (page != null) {
page.url = link.getAddress();
_this.cache.cacheUrl(page, _this.options.debugMode);
_this.triggerEvent('pagePreloaded');
}
resolve(_this.cache.getPage(link.getAddress()));
}
}
});
}
});
} else {
resolve(_this.cache.getPage(link.getAddress()));
}
});
};

/***/ }),
Expand Down
Loading

0 comments on commit 33367a1

Please sign in to comment.