Fixes around render cache

This commit is contained in:
Bryan Ashby 2018-07-04 18:48:35 -06:00
parent 514edb984f
commit 2408d4c5c0
1 changed files with 12 additions and 0 deletions

View File

@ -102,6 +102,8 @@ MenuView.prototype.setItems = function(items) {
if(this.complexItems) {
this.itemFormat = this.itemFormat || '{text}';
}
this.invalidateRenderCache();
}
};
@ -110,11 +112,19 @@ MenuView.prototype.getRenderCacheItem = function(index, focusItem = false) {
return item && item[focusItem ? 'focus' : 'standard'];
};
MenuView.prototype.removeRenderCacheItem = function(index) {
delete this.renderCache[index];
};
MenuView.prototype.setRenderCacheItem = function(index, rendered, focusItem = false) {
this.renderCache[index] = this.renderCache[index] || {};
this.renderCache[index][focusItem ? 'focus' : 'standard'] = rendered;
};
MenuView.prototype.invalidateRenderCache = function() {
this.renderCache = {};
};
MenuView.prototype.setSort = function(sort) {
if(this.sorted || !Array.isArray(this.items) || 0 === this.items.length) {
return;
@ -152,6 +162,8 @@ MenuView.prototype.removeItem = function(index) {
this.focusedItemIndex = Math.max(this.focusedItemIndex - 1, 0);
}
this.removeRenderCacheItem(index);
this.positionCacheExpired = true;
};