Skip to content

Commit

Permalink
v0.0.5
Browse files Browse the repository at this point in the history
* Fix check for calling XHR before make AJAX call to prevent multiple scroll events cause fail events `reject('previous XHR is calling.')`.
  • Loading branch information
ve3 committed May 4, 2022
1 parent 1acb4b6 commit 906b797
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rundiz-scroll-pagination",
"version": "0.0.4",
"version": "0.0.5",
"description": "Scroll down the page and automatically call to get next page contents.",
"main": "index.js",
"directories": {
Expand Down
72 changes: 37 additions & 35 deletions src/RundizScrollPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @author Vee W.
* @license MIT.
* @version 0.0.3
* @version 0.0.5
*/


Expand Down Expand Up @@ -317,43 +317,45 @@ class RundizScrollPagination {
}
);*/

// begins ajax pagination.
this.ajaxPagination()
.then((responseObject) => {
responseObject.rdScrollPaginationCurrentPageOffset = thisClass.previousStartOffset;
document.dispatchEvent(
new CustomEvent(
'rdScrollPagination.done', {'detail': responseObject}
)
);
// trigger on scroll for in case that there are space left in the bottom of visible area.
// trigger will try to load next ajax page if there are more space left.
thisClass.triggerOnScroll();

return Promise.resolve(responseObject);
})
.catch((responseObject) => {
// .catch() must be after .then(). see https://stackoverflow.com/a/42028776/128761
if (typeof(responseObject) === 'object') {
// if responseObject is not an object.
// due to ajax error can throw a string message, check before assign.
if (thisClass.callingXHR === false) {
// begins ajax pagination.
this.ajaxPagination()
.then((responseObject) => {
responseObject.rdScrollPaginationCurrentPageOffset = thisClass.previousStartOffset;
}

document.dispatchEvent(
new CustomEvent(
'rdScrollPagination.fail', {'detail': responseObject}
)
);
document.dispatchEvent(
new CustomEvent(
'rdScrollPagination.done', {'detail': responseObject}
)
);
// trigger on scroll for in case that there are space left in the bottom of visible area.
// trigger will try to load next ajax page if there are more space left.
thisClass.triggerOnScroll();

return Promise.resolve(responseObject);
})
.catch((responseObject) => {
// .catch() must be after .then(). see https://stackoverflow.com/a/42028776/128761
if (typeof(responseObject) === 'object') {
// if responseObject is not an object.
// due to ajax error can throw a string message, check before assign.
responseObject.rdScrollPaginationCurrentPageOffset = thisClass.previousStartOffset;
}

return Promise.reject(responseObject)
.then(() => {
// not called.
}, (responseObject) => {
// prevent uncaught error.
document.dispatchEvent(
new CustomEvent(
'rdScrollPagination.fail', {'detail': responseObject}
)
);

return Promise.reject(responseObject)
.then(() => {
// not called.
}, (responseObject) => {
// prevent uncaught error.
});
});
});
}
}// endif callingXHR check
}// endif; total scroll > document scroll height.
}// checkScrollAndMakeXHR


Expand Down

0 comments on commit 906b797

Please sign in to comment.