From 8a790a6fe2cb68d2f1c09aad6193ce8b01266e1d Mon Sep 17 00:00:00 2001 From: khlieng Date: Wed, 11 Feb 2015 02:48:28 +0100 Subject: [PATCH] Persist input history in localStorage --- client/src/js/stores/inputHistory.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/src/js/stores/inputHistory.js b/client/src/js/stores/inputHistory.js index 719cff42..462d344f 100644 --- a/client/src/js/stores/inputHistory.js +++ b/client/src/js/stores/inputHistory.js @@ -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); } },