YES converted over local storage

This commit is contained in:
Peter Cottle 2015-04-04 11:06:23 -07:00
parent ca938ec79e
commit 3a710c8ab4
3 changed files with 59 additions and 48 deletions

View file

@ -8,6 +8,8 @@ var assign = require('object-assign');
var ActionTypes = AppConstants.ActionTypes;
var COMMAND_HISTORY_KEY = 'lgb_CommandHistory';
var COMMAND_HISTORY_MAX_LENGTH = 100;
var COMMAND_HISTORY_TO_KEEP = 10;
var _commandHistory = [];
try {
@ -17,7 +19,16 @@ try {
} catch (e) {
}
var _saveToLocalStorage = function() {
function _checkForSize() {
// if our command line history is too big...
if (_commandHistory.length > COMMAND_HISTORY_MAX_LENGTH) {
// grab the last 10
_commandHistory =
_commandHistory.slice(0, COMMAND_HISTORY_TO_KEEP);
}
}
function _saveToLocalStorage() {
try {
localStorage.setItem(
COMMAND_HISTORY_KEY,
@ -25,7 +36,7 @@ var _saveToLocalStorage = function() {
);
} catch (e) {
}
};
}
var CommandLineStore = assign(
{},
@ -33,6 +44,10 @@ EventEmitter.prototype,
AppConstants.StoreSubscribePrototype,
{
getMaxHistoryLength: function() {
return COMMAND_HISTORY_MAX_LENGTH;
},
getCommandHistoryLength: function() {
return _commandHistory.length;
},
@ -47,7 +62,8 @@ AppConstants.StoreSubscribePrototype,
switch (action.type) {
case ActionTypes.SUBMIT_COMMAND:
_commandHistory.push(action.text);
_commandHistory.unshift(String(action.text));
_checkForSize();
_saveToLocalStorage();
shouldInform = true;
break;