Created
May 23, 2023 12:34
-
-
Save M-ZubairAhmed/c348d70afe1adcf8d774c9ad983c671b to your computer and use it in GitHub Desktop.
Saving the redux store in file exposed on window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save the console function in the console once | |
(function (console) { | |
console.save = function (data, filename) { | |
if (!data) { | |
console.error('Console.save: No data') | |
return | |
} | |
if (!filename) { | |
filename = 'console.json' | |
} | |
if (typeof data === 'object') { | |
data = JSON.stringify(data, undefined, 4) | |
} | |
var blob = new Blob([data], { type: 'text/json' }) | |
var mouseEvent = document.createEvent('MouseEvents') | |
var anchorElement = document.createElement('a') | |
anchorElement.download = filename | |
anchorElement.href = window.URL.createObjectURL(blob) | |
anchorElement.dataset.downloadurl = [ | |
'text/json', | |
anchorElement.download, | |
anchorElement.href | |
].join(':') | |
mouseEvent.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) | |
anchorElement.dispatchEvent(mouseEvent) | |
} | |
})(console) | |
// Usage for redux store | |
// console.save(window.store.getState(), 'redux-store-1.json') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment