FIX: Use much less aggressive cloaking

This commit is contained in:
Robin Ward 2016-03-01 16:50:46 -05:00
parent e6b95e56d7
commit bff965327c
1 changed files with 11 additions and 6 deletions

View File

@ -41,8 +41,9 @@ export default MountWidget.extend({
const $w = $(window); const $w = $(window);
const windowHeight = window.innerHeight ? window.innerHeight : $w.height(); const windowHeight = window.innerHeight ? window.innerHeight : $w.height();
const slack = Math.round(windowHeight * 15); const slack = Math.round(windowHeight * 5);
const onscreen = []; const onscreen = [];
const nearby = [];
let windowTop = $w.scrollTop(); let windowTop = $w.scrollTop();
@ -72,6 +73,7 @@ export default MountWidget.extend({
if (viewBottom > windowTop && viewTop <= windowBottom) { if (viewBottom > windowTop && viewTop <= windowBottom) {
onscreen.push(bottomView); onscreen.push(bottomView);
} }
nearby.push(bottomView);
bottomView++; bottomView++;
} }
@ -114,20 +116,23 @@ export default MountWidget.extend({
} }
const onscreenPostNumbers = []; const onscreenPostNumbers = [];
const prev = this._previouslyOnscreen; const prev = this._previouslyNearby;
const newPrev = {}; const newPrev = {};
onscreen.forEach(idx => { nearby.forEach(idx => {
const post = posts.objectAt(idx); const post = posts.objectAt(idx);
const postNumber = post.post_number; const postNumber = post.post_number;
delete prev[postNumber]; delete prev[postNumber];
onscreenPostNumbers.push(postNumber);
if (onscreen.indexOf(idx) !== -1) {
onscreenPostNumbers.push(postNumber);
}
newPrev[postNumber] = post; newPrev[postNumber] = post;
uncloak(post, this); uncloak(post, this);
}); });
Object.keys(prev).forEach(pn => cloak(prev[pn], this)); Object.keys(prev).forEach(pn => cloak(prev[pn], this));
this._previouslyOnscreen = newPrev; this._previouslyNearby = newPrev;
this.screenTrack.setOnscreen(onscreenPostNumbers); this.screenTrack.setOnscreen(onscreenPostNumbers);
}, },
@ -139,7 +144,7 @@ export default MountWidget.extend({
this._super(); this._super();
const debouncedScroll = () => Ember.run.debounce(this, this._scrollTriggered, 10); const debouncedScroll = () => Ember.run.debounce(this, this._scrollTriggered, 10);
this._previouslyOnscreen = {}; this._previouslyNearby = {};
this.appEvents.on('post-stream:refresh', debouncedScroll); this.appEvents.on('post-stream:refresh', debouncedScroll);
$(document).bind('touchmove.post-stream', debouncedScroll); $(document).bind('touchmove.post-stream', debouncedScroll);