ES6 cleanup

This commit is contained in:
Bryan Ashby 2016-07-02 20:02:00 -06:00
parent 8fb5a2dd1e
commit 5a5b39f3a4
1 changed files with 24 additions and 22 deletions

View File

@ -1,13 +1,14 @@
/* jslint node: true */ /* jslint node: true */
'use strict'; 'use strict';
var View = require('./view.js').View; // ENiGMA½
var ansi = require('./ansi_term.js'); const View = require('./view.js').View;
var miscUtil = require('./misc_util.js'); const miscUtil = require('./misc_util.js');
var util = require('util'); // deps
var assert = require('assert'); const util = require('util');
var _ = require('lodash'); const assert = require('assert');
const _ = require('lodash');
exports.MenuView = MenuView; exports.MenuView = MenuView;
@ -17,7 +18,7 @@ function MenuView(options) {
View.call(this, options); View.call(this, options);
var self = this; const self = this;
if(options.items) { if(options.items) {
this.setItems(options.items); this.setItems(options.items);
@ -47,7 +48,7 @@ function MenuView(options) {
this.getHotKeyItemIndex = function(ch) { this.getHotKeyItemIndex = function(ch) {
if(ch && self.hotKeys) { if(ch && self.hotKeys) {
var keyIndex = self.hotKeys[self.caseInsensitiveHotKeys ? ch.toLowerCase() : ch]; const keyIndex = self.hotKeys[self.caseInsensitiveHotKeys ? ch.toLowerCase() : ch];
if(_.isNumber(keyIndex)) { if(_.isNumber(keyIndex)) {
return keyIndex; return keyIndex;
} }
@ -59,10 +60,11 @@ function MenuView(options) {
util.inherits(MenuView, View); util.inherits(MenuView, View);
MenuView.prototype.setItems = function(items) { MenuView.prototype.setItems = function(items) {
var self = this; const self = this;
if(items) { if(items) {
this.items = []; // :TODO: better way? this.items = [];
items.forEach(function item(itemText) { items.forEach( itemText => {
self.items.push( { text : itemText } ); self.items.push( { text : itemText } );
}); });
} }
@ -73,8 +75,8 @@ MenuView.prototype.getCount = function() {
}; };
MenuView.prototype.getItems = function() { MenuView.prototype.getItems = function() {
return _.map(this.items, function itemIter(i) { return this.items.map( item => {
return i.text; return item.text;
}); });
}; };
@ -97,7 +99,7 @@ MenuView.prototype.setFocusItemIndex = function(index) {
}; };
MenuView.prototype.onKeyPress = function(ch, key) { MenuView.prototype.onKeyPress = function(ch, key) {
var itemIndex = this.getHotKeyItemIndex(ch); const itemIndex = this.getHotKeyItemIndex(ch);
if(itemIndex >= 0) { if(itemIndex >= 0) {
this.setFocusItemIndex(itemIndex); this.setFocusItemIndex(itemIndex);
@ -110,11 +112,11 @@ MenuView.prototype.onKeyPress = function(ch, key) {
}; };
MenuView.prototype.setFocusItems = function(items) { MenuView.prototype.setFocusItems = function(items) {
var self = this; const self = this;
if(items) { if(items) {
this.focusItems = []; this.focusItems = [];
items.forEach(function item(itemText) { items.forEach( itemText => {
self.focusItems.push( { text : itemText } ); self.focusItems.push( { text : itemText } );
}); });
} }