Persist input history in localStorage
This commit is contained in:
parent
1faf310ebd
commit
8a790a6fe2
@ -7,6 +7,11 @@ var HISTORY_MAX_LENGTH = 128;
|
|||||||
|
|
||||||
var history = [];
|
var history = [];
|
||||||
var index = -1;
|
var index = -1;
|
||||||
|
var stored = localStorage.inputHistory;
|
||||||
|
|
||||||
|
if (stored) {
|
||||||
|
history = JSON.parse(stored);
|
||||||
|
}
|
||||||
|
|
||||||
var inputHistoryStore = Reflux.createStore({
|
var inputHistoryStore = Reflux.createStore({
|
||||||
init: function() {
|
init: function() {
|
||||||
@ -16,10 +21,12 @@ var inputHistoryStore = Reflux.createStore({
|
|||||||
add: function(line) {
|
add: function(line) {
|
||||||
if (line.trim() && line !== history[0]) {
|
if (line.trim() && line !== history[0]) {
|
||||||
history.unshift(line);
|
history.unshift(line);
|
||||||
|
|
||||||
if (history.length > HISTORY_MAX_LENGTH) {
|
if (history.length > HISTORY_MAX_LENGTH) {
|
||||||
history.pop();
|
history.pop();
|
||||||
}
|
}
|
||||||
this.trigger(history[index]);
|
|
||||||
|
localStorage.inputHistory = JSON.stringify(history);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user