FIX: Upwards scrolling was broken in a topic

This commit is contained in:
Robin Ward 2016-02-10 13:40:31 -05:00
parent ea98a4366e
commit 88c104bb83
2 changed files with 14 additions and 6 deletions

View File

@ -6,6 +6,7 @@ export default Ember.Component.extend({
_rootNode: null, _rootNode: null,
_timeout: null, _timeout: null,
_widgetClass: null, _widgetClass: null,
_afterRender: null,
init() { init() {
this._super(); this._super();
@ -24,7 +25,11 @@ export default Ember.Component.extend({
Ember.run.cancel(this._timeout); Ember.run.cancel(this._timeout);
}, },
queueRerender() { queueRerender(callback) {
if (callback && !this._afterRender) {
this._afterRender = callback;
}
Ember.run.scheduleOnce('render', this, this.rerenderWidget); Ember.run.scheduleOnce('render', this, this.rerenderWidget);
}, },
@ -41,6 +46,11 @@ export default Ember.Component.extend({
this._rootNode = patch(this._rootNode, patches); this._rootNode = patch(this._rootNode, patches);
this._tree = newTree; this._tree = newTree;
console.log('render: ', new Date().getTime() - t0); console.log('render: ', new Date().getTime() - t0);
if (this._afterRender) {
this._afterRender();
this._afterRender = null;
}
} }
} }

View File

@ -77,7 +77,7 @@ export default MountWidget.extend({
const posts = this.posts; const posts = this.posts;
if (onscreen.length) { if (onscreen.length) {
const refresh = () => this.queueRerender(); const refresh = cb => this.queueRerender(cb);
const first = posts.objectAt(onscreen[0]); const first = posts.objectAt(onscreen[0]);
if (this._topVisible !== first) { if (this._topVisible !== first) {
this._topVisible = first; this._topVisible = first;
@ -89,10 +89,8 @@ export default MountWidget.extend({
const distToElement = elemPos ? $body.scrollTop() - elemPos.top : 0; const distToElement = elemPos ? $body.scrollTop() - elemPos.top : 0;
const topRefresh = () => { const topRefresh = () => {
refresh(); refresh(() => {
const $refreshedElem = $(`#${elemId}`);
Ember.run.next(() => {
const $refreshedElem = $(elemId);
// Quickly going back might mean the element is destroyed // Quickly going back might mean the element is destroyed
const position = $refreshedElem.position(); const position = $refreshedElem.position();