Skip to content

Instantly share code, notes, and snippets.

@leongaban
Created January 6, 2017 17:16
Show Gist options
  • Save leongaban/bcde2ac54c9f4ee1fdab2215498d576a to your computer and use it in GitHub Desktop.
Save leongaban/bcde2ac54c9f4ee1fdab2215498d576a to your computer and use it in GitHub Desktop.
InfiniteScrolling
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