Skip to content

Commit

Permalink
Merge pull request #322 from lorenzos/concatenated-local-storage
Browse files Browse the repository at this point in the history
Persisted "Show content of concatenated modules" with localStorage
  • Loading branch information
th0r authored Apr 13, 2020
2 parents acf2d1c + f8f4049 commit 29beb70
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 29beb70

Please sign in to comment.