-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
32 lines (25 loc) · 847 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const { saveAs } = require('file-saver');
const download = (content, fileName, mime = "application/json") => {
const blob = new Blob([JSON.stringify(content)], { type: mime });
saveAs(blob, fileName);
};
const vuexHistory = [];
export default function(options) {
if (options === void 0) options = {};
let fileName = options.fileName;
if (fileName === void 0) fileName = "state-dump.json";
let mutationListener = options.mutationListener;
if (mutationListener === void 0) mutationListener = "exportToJson";
return store => {
store.subscribe((mutation, state) => {
vuexHistory.push(mutation);
if (mutation.type === mutationListener) {
const formattedState = {
payload: JSON.stringify(vuexHistory),
state
};
download(formattedState, fileName);
}
});
};
}