Created
January 6, 2017 17:16
-
-
Save leongaban/bcde2ac54c9f4ee1fdab2215498d576a to your computer and use it in GitHub Desktop.
InfiniteScrolling
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
const maxlimitCheck = () => this.tags.length >= TOTAL_TAGS; | |
const checkScrollLimit = () => { | |
if (!LIMIT_REACHED) { | |
const scrollingTrue = true; | |
PARAMS.start += this.limit; | |
maxlimitCheck() ? LIMIT_REACHED = true : fetchTags(scrollingTrue); | |
} | |
}; | |
const reachedBottom = () => tagsCol.scrollHeight - tagsCol.scrollTop === tagsCol.offsetHeight; | |
const scrollingTags = () => reachedBottom() ? checkScrollLimit() : null; | |
const fillTagsList = (tags, scrolling) => { | |
const modifiedTags = R.map(R.assoc('ticker', this.ticker))(tags.array); | |
const coloredTags = TagsFactory.setTagColors(modifiedTags, $state.params); | |
scrolling ? R.forEach(pushInTags, coloredTags) : this.tags = coloredTags; | |
return this.tags; | |
}; | |
const attachTags = R.curry((scrolling = false, tags) => { | |
TOTAL_TAGS = tags.total; | |
this.tags = fillTagsList(tags, scrolling); | |
return this.tags; | |
}); | |
// http://codereview.stackexchange.com/questions/151767/how-to-better-organize-the-declarations-of-these-functions/151770#151770 | |
const fetchTags = (scrolling = false) => { | |
LIMIT_REACHED = false; | |
const curriedAttachTags = (tags) => attachTags(scrolling, tags); | |
return GetTagsFactory.getTags(false, Util.encodeTicker(this.ticker), PARAMS).then(curriedAttachTags); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment