1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11 } = require("resource://devtools/client/webconsole/constants.js");
13 const historyActions
= require("resource://devtools/client/webconsole/actions/history.js");
15 loader
.lazyRequireGetter(
18 "resource://devtools/shared/async-storage.js"
22 * History persistence middleware is responsible for loading
23 * and maintaining history of executed expressions in JSTerm.
25 function historyPersistenceMiddleware(webConsoleUI
, store
) {
26 let historyLoaded
= false;
27 asyncStorage
.getItem("webConsoleHistory").then(
29 if (Array
.isArray(value
)) {
30 store
.dispatch(historyActions
.historyLoaded(value
));
40 return next
=> action
=> {
41 const res
= next(action
);
43 const triggerStoreActions
= [
49 // Save the current history entries when modified, but wait till
50 // entries from the previous session are loaded.
52 webConsoleUI
.hud
?.commands
?.targetCommand
?.targetFront
?.targetForm
|| {};
57 triggerStoreActions
.includes(action
.type
)
59 const state
= store
.getState();
61 .setItem("webConsoleHistory", state
.history
.entries
)
63 console
.error("Error when saving WebConsole input history", e
);
71 module
.exports
= historyPersistenceMiddleware
;