Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persisted "Show content of concatenated modules" with localStorage #322

Merged
merged 6 commits into from Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,9 @@ _Note: Gaps between patch versions are faulty, broken or test releases._

<!-- Add changelog entries for new changes under this section -->

* **Improvement**
* Persist "Show content of concatenated modules" option ([#322](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/322) by [@lorenzos](https://github.com/lorenzos))

## 3.6.1

* **Bug Fix**
Expand Down
6 changes: 6 additions & 0 deletions client/components/ModulesTreemap.jsx
Expand Up @@ -5,6 +5,7 @@ import {computed} from 'mobx';
import {observer} from 'mobx-preact';

import {isChunkParsed} from '../utils';
import localStorage from '../localStorage';
import Treemap from './Treemap';
import Tooltip from './Tooltip';
import Switcher from './Switcher';
Expand Down Expand Up @@ -208,6 +209,11 @@ export default class ModulesTreemap extends Component {

handleConcatenatedModulesContentToggle = flag => {
store.showConcatenatedModulesContent = flag;
if (flag) {
localStorage.setItem('showConcatenatedModulesContent', true);
} else {
localStorage.removeItem('showConcatenatedModulesContent');
}
}

handleChunkContextMenuHide = () => {
Expand Down
25 changes: 25 additions & 0 deletions client/localStorage.js
@@ -0,0 +1,25 @@
const KEY_PREFIX = 'wba';

export default {

getItem(key) {
try {
return JSON.parse(window.localStorage.getItem(`${KEY_PREFIX}.${key}`));
} catch (err) {
return null;
}
},

setItem(key, value) {
try {
window.localStorage.setItem(`${KEY_PREFIX}.${key}`, JSON.stringify(value));
} catch (err) { /* ignored */ }
},

removeItem(key) {
try {
window.localStorage.removeItem(`${KEY_PREFIX}.${key}`);
} catch (err) { /* ignored */ }
}

};
3 changes: 2 additions & 1 deletion client/store.js
@@ -1,5 +1,6 @@
import {observable, computed} from 'mobx';
import {isChunkParsed, walkModules} from './utils';
import localStorage from './localStorage';

export class Store {
cid = 0;
Expand All @@ -10,7 +11,7 @@ export class Store {
@observable searchQuery = '';
@observable defaultSize;
@observable selectedSize;
@observable showConcatenatedModulesContent = false;
@observable showConcatenatedModulesContent = (localStorage.getItem('showConcatenatedModulesContent') === true);

setModules(modules) {
walkModules(modules, module => {
Expand Down