Skip to content

Commit

Permalink
ENYO-2533: Move deferred reset & refresh logic to VDR
Browse files Browse the repository at this point in the history
NewDataList has some logic to defer refreshing and resetting when
the list is not showing.

This logic would apply equally to VirtualDataRepeater, so we'll
move it there.

Enyo-DCO-1.1-Signed-Off-By: Gray Norton (gray.norton@lge.com)
  • Loading branch information
Gray Norton committed Sep 15, 2015
1 parent 8d78de3 commit 8c4f9ca
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 54 deletions.
61 changes: 15 additions & 46 deletions src/NewDataList.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,57 +323,26 @@ module.exports = kind({
/**
* @private
*/
showingChangedHandler: kind.inherit(function (sup) {
return function () {
if (this.needsReset) {
this.reset();
}
else if (this.needsRefresh) {
this.refresh();
}
return sup.apply(this, arguments);
};
}),
collectionResetHandler: function () {
this.calcBoundaries();
},

/**
* @private
*/
refresh: kind.inherit(function (sup) {
return function () {
if (this.getAbsoluteShowing()) {
if (arguments[1] === 'reset') {
this.calcBoundaries();
}
this.needsRefresh = false;
sup.apply(this, arguments);
}
else {
this.needsRefresh = true;
}
};
}),

/**
* @private
*/
reset: kind.inherit(function (sup) {
init: kind.inherit(function (sup) {
return function () {
var v;
if (this.getAbsoluteShowing()) {
v = (this.direction === 'vertical');
this.set('scrollTop', 0);
this.set('scrollLeft', 0);
this.set('vertical', v ? 'auto' : 'hidden');
this.set('horizontal', v ? 'hidden' : 'auto');
this.calculateMetrics();
this.calcBoundaries();
this.first = 0;
this.needsReset = false;
sup.apply(this, arguments);
}
else {
this.needsReset = true;
}
var v = (this.direction === 'vertical');

this.set('scrollTop', 0);
this.set('scrollLeft', 0);
this.set('vertical', v ? 'auto' : 'hidden');
this.set('horizontal', v ? 'hidden' : 'auto');
this.calculateMetrics();
this.calcBoundaries();
this.first = 0;

sup.apply(this, arguments);
};
})
});
45 changes: 37 additions & 8 deletions src/VirtualDataRepeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ module.exports = kind({
// reorderNodes: false,

reset: function () {
this.init();
this.destroyClientControls();
this.setExtent();
if (this.getAbsoluteShowing()) {
this.init();
this.destroyClientControls();
this.setExtent();
this._needsReset = false;
}
else {
this._needsReset = true;
}
},

init: function () {
Expand Down Expand Up @@ -64,15 +70,38 @@ module.exports = kind({
this.notify('numItems', pn, this.numItems);
}
},

refresh: function (immediate) {
if (!this.hasInitialized) return this.reset();

this.stabilizeExtent();
refresh: function () {
if (!this.hasInitialized) return this.reset();

this.doIt();
if (this.getAbsoluteShowing()) {
if (arguments[1] === 'reset' && typeof this.collectionResetHandler === 'function') {

This comment has been minimized.

Copy link
@webOS101

webOS101 Oct 30, 2015

Member

Is there a reason you got rid of the argument and then used arguments[1]? Didn't want an unused arguments[0]? Also, I couldn't find any place (outside of old DataList) that indicates there could be more than one argument but it's not documented there so I'm not sure what role that plays.

This comment has been minimized.

Copy link
@graynorton

graynorton Oct 30, 2015

Member

The immediate argument is actually restored in a later commit in the same PR. I think there are some notes on the history in one of the commit messages.

The arguments[1] bit is unrelated, actually. enyo/DataRepeater calls refresh() directly as an event handler for collection reset events, and we use arguments[1] to detect that case (since we're looking for the event name, and it's always passed as the second argument to an event handler.

this.collectionResetHandler();
}
this.stabilizeExtent();
this.doIt();
this._needsRefresh = false;
}
else {
this._needsRefresh = true;
}
},

/**
* @private
*/
showingChangedHandler: kind.inherit(function (sup) {
return function () {
if (this._needsReset) {
this.reset();
}
else if (this._needsRefresh) {
this.refresh();
}
return sup.apply(this, arguments);
};
}),

childForIndex: function(idx) {
return this.childrenByIndex[idx];
},
Expand Down

0 comments on commit 8c4f9ca

Please sign in to comment.