Created
May 24, 2020 10:12
-
-
Save sudikrt/144d6981a5853ffdff4b44a56dd5aabf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| this.superAfterRender(); | |
| // this is done in renderer because we don't get access to the window element in the helper js. | |
| var didScroll = false; | |
| window.onscroll = function() { | |
| didScroll = true; | |
| }; | |
| window.addEventListener('scroll', function() { | |
| didScroll = true; | |
| }); | |
| // periodically attach the scroll event listener so that we aren't taking action for all events | |
| var idOfSetInterval = window.setInterval( $A.getCallback( function() { | |
| // Since setInterval happens outside the component's lifecycle | |
| // We need to check if component exist, only then logic needs to be processed | |
| if ( didScroll && component.isValid() && component.get("v.enableInfiniteLoading")==true | |
| && component.get ('v.selectedTab') === "ACTIVE") { | |
| didScroll = false; | |
| // adapted from stackoverflow to detect when user has scrolled sufficiently to end of document | |
| if ((window['scrollY'] >= document.body['scrollHeight'] - window['outerHeight'] - 800 ) || | |
| ((window.innerHeight + Math.ceil(window.pageYOffset + 1)) >= document.body.offsetHeight)) { | |
| component.set ('v.lazyLoading', true); | |
| console.log('Triggering lazy load'); | |
| component.set("v.lazyLoadingInProgress",true); | |
| //Need to add this one second delay so the view has time to render the variable change before | |
| //the rows are rendered | |
| window.setTimeout($A.getCallback(function(){ | |
| helper.loadPageData(component); | |
| }), 1000); | |
| //component.set("v.enableInfiniteLoading", false); | |
| } | |
| } | |
| }), 500 ); | |
| // Save the id.We need to use in unrender to remove the setInterval() | |
| component.set( "v.intervalId", idOfSetInterval ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment