Conceptual MenuItem caching - WIP for testing, will impl. in others if it seems good

This commit is contained in:
Bryan Ashby 2018-02-01 20:29:26 -07:00
parent a121d60c1b
commit 548ff41467
2 changed files with 21 additions and 3 deletions

View file

@ -29,6 +29,8 @@ function MenuView(options) {
this.items = [];
}
this.renderCache = {};
this.caseInsensitiveHotKeys = miscUtil.valueWithDefault(options.caseInsensitiveHotKeys, true);
this.setHotKeys(options.hotKeys);
@ -65,6 +67,7 @@ util.inherits(MenuView, View);
MenuView.prototype.setItems = function(items) {
if(Array.isArray(items)) {
this.sorted = false;
this.renderCache = {};
//
// Items can be an array of strings or an array of objects.
@ -98,6 +101,16 @@ MenuView.prototype.setItems = function(items) {
}
};
MenuView.prototype.getRenderCacheItem = function(index, focusItem = false) {
const item = this.renderCache[index];
return item && item[focusItem ? 'focus' : 'standard'];
};
MenuView.prototype.setRenderCacheItem = function(index, rendered, focusItem = false) {
this.renderCache[index] = this.renderCache[index] || {};
this.renderCache[index][focusItem ? 'focus' : 'standard'] = rendered;
};
MenuView.prototype.setSort = function(sort) {
if(this.sorted || !Array.isArray(this.items) || 0 === this.items.length) {
return;