Persist input history in localStorage

This commit is contained in:
khlieng 2015-02-11 02:48:28 +01:00
parent 1faf310ebd
commit 8a790a6fe2

View File

@ -7,6 +7,11 @@ var HISTORY_MAX_LENGTH = 128;
var history = [];
var index = -1;
var stored = localStorage.inputHistory;
if (stored) {
history = JSON.parse(stored);
}
var inputHistoryStore = Reflux.createStore({
init: function() {
@ -16,10 +21,12 @@ var inputHistoryStore = Reflux.createStore({
add: function(line) {
if (line.trim() && line !== history[0]) {
history.unshift(line);
if (history.length > HISTORY_MAX_LENGTH) {
history.pop();
}
this.trigger(history[index]);
localStorage.inputHistory = JSON.stringify(history);
}
},