Skip to content

Commit 6e9d8ff

Browse files
committed
Remove default values from app preference on persist
1 parent 3edb7a0 commit 6e9d8ff

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/models/AppPreference.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@ export default class AppPreference extends Record({
88
showBookmarks: true,
99
theme: THEMES.getDefault(),
1010
}) {
11-
merge(map) {
12-
return new AppPreference(super.merge(map));
13-
}
11+
static DEFAULT = new AppPreference()
1412
}

src/repositories/AppPreferenceRepository.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,21 @@ export default class AppPreferenceRepository {
2525
}
2626
}
2727

28+
/**
29+
* @param {AppPreference} appPreference
30+
*/
2831
save(appPreference) {
29-
const json = appPreference.toJS();
30-
localStorage.setItem(APP_PREFERENCE, JSON.stringify({
31-
...json,
32-
theme: json.theme.id,
33-
}));
32+
const json = appPreference.toMap()
33+
.filter((value, key) => value !== AppPreference.DEFAULT.get(key))
34+
.map((value, key) => {
35+
switch (key) {
36+
case 'theme':
37+
return value.id;
38+
default:
39+
return value;
40+
}
41+
});
42+
localStorage.setItem(APP_PREFERENCE, JSON.stringify(json));
3443

3544
// clean up old key
3645
localStorage.removeItem(HIDDEN_COMPONENTS);

0 commit comments

Comments
 (0)