Skip to content

Commit

Permalink
Apply suggestions from code review (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzos committed Oct 11, 2019
1 parent b4a48f3 commit 9823e7c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
3 changes: 2 additions & 1 deletion client/components/ModulesTreemap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import filesize from 'filesize';
import {computed} from 'mobx';
import {observer} from 'mobx-preact';

import {isChunkParsed, localStorage} from '../utils';
import {isChunkParsed} from '../utils';
import localStorage from '../localStorage';
import Treemap from './Treemap';
import Tooltip from './Tooltip';
import Switcher from './Switcher';
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, localStorage} from './utils';
import {isChunkParsed, walkModules} from './utils';
import localStorage from './localStorage';

export class Store {
cid = 0;
Expand Down
24 changes: 0 additions & 24 deletions client/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,3 @@ export function walkModules(modules, cb) {
export function elementIsOutside(elem, container) {
return !(elem === container || container.contains(elem));
}

export const localStorage = {

getItem(k) {
try {
return window.localStorage.getItem(k);
} catch (x) {
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);
} catch (err) { /* ignored */ }
}

};

0 comments on commit 9823e7c

Please sign in to comment.