Skip to content

Commit 7b9a7ab

Browse files
chore: update mobx
1 parent 8903671 commit 7b9a7ab

6 files changed

Lines changed: 133 additions & 109 deletions

File tree

client/components/ModulesTreemap.jsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component } from "preact";
22
import { filesize } from "filesize";
3-
import { computed } from "mobx";
3+
import { computed, makeObservable } from "mobx";
44
import { observer } from "mobx-react";
55

66
import { isChunkParsed } from "../utils";
@@ -37,8 +37,7 @@ function getSizeSwitchItems() {
3737
return items;
3838
}
3939

40-
@observer
41-
export default class ModulesTreemap extends Component {
40+
class ModulesTreemap extends Component {
4241
mouseCoords = {
4342
x: 0,
4443
y: 0,
@@ -53,6 +52,18 @@ export default class ModulesTreemap extends Component {
5352
tooltipContent: null,
5453
};
5554

55+
constructor() {
56+
super();
57+
58+
makeObservable(this, {
59+
sizeSwitchItems: computed,
60+
activeSizeItem: computed,
61+
chunkItems: computed,
62+
highlightedModules: computed,
63+
foundModulesInfo: computed
64+
});
65+
}
66+
5667
componentDidMount() {
5768
document.addEventListener("mousemove", this.handleMouseMove, true);
5869
}
@@ -192,17 +203,17 @@ export default class ModulesTreemap extends Component {
192203
return [`${label} (`, <strong>{filesize(size)}</strong>, ")"];
193204
};
194205

195-
@computed get sizeSwitchItems() {
206+
get sizeSwitchItems() {
196207
return store.hasParsedSizes
197208
? getSizeSwitchItems()
198209
: getSizeSwitchItems().slice(0, 1);
199210
}
200211

201-
@computed get activeSizeItem() {
212+
get activeSizeItem() {
202213
return this.sizeSwitchItems.find((item) => item.prop === store.activeSize);
203214
}
204215

205-
@computed get chunkItems() {
216+
get chunkItems() {
206217
const { allChunks, activeSize } = store;
207218
let chunkItems = [...allChunks];
208219

@@ -217,11 +228,11 @@ export default class ModulesTreemap extends Component {
217228
return chunkItems;
218229
}
219230

220-
@computed get highlightedModules() {
231+
get highlightedModules() {
221232
return new Set(store.foundModules);
222233
}
223234

224-
@computed get foundModulesInfo() {
235+
get foundModulesInfo() {
225236
if (!store.isSearching) {
226237
// `&nbsp;` to reserve space
227238
return "\u00A0";
@@ -383,3 +394,5 @@ export default class ModulesTreemap extends Component {
383394
);
384395
}
385396
}
397+
398+
export default observer(ModulesTreemap);

client/components/ThemeToggle.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import Button from "./Button";
66
import Icon from "./Icon";
77
import { store } from "../store";
88

9-
@observer
10-
export default class ThemeToggle extends Component {
9+
class ThemeToggle extends Component {
1110
render() {
1211
const { darkMode } = store;
1312

@@ -27,3 +26,5 @@ export default class ThemeToggle extends Component {
2726
store.toggleDarkMode();
2827
};
2928
}
29+
30+
export default observer(ThemeToggle);

client/store.js

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { observable, computed } from "mobx";
1+
import { observable, computed, makeObservable } from "mobx";
22
import { isChunkParsed, walkModules } from "./utils";
33
import localStorage from "./localStorage";
44

@@ -12,14 +12,14 @@ export class Store {
1212
"zstdSize",
1313
]);
1414

15-
@observable.ref allChunks;
16-
@observable.shallow selectedChunks;
17-
@observable searchQuery = "";
18-
@observable defaultSize;
19-
@observable selectedSize;
20-
@observable showConcatenatedModulesContent =
15+
allChunks;
16+
selectedChunks;
17+
searchQuery = "";
18+
defaultSize;
19+
selectedSize;
20+
showConcatenatedModulesContent =
2121
localStorage.getItem("showConcatenatedModulesContent") === true;
22-
@observable darkMode = (() => {
22+
darkMode = (() => {
2323
const systemPrefersDark = window.matchMedia(
2424
"(prefers-color-scheme: dark)",
2525
).matches;
@@ -34,6 +34,31 @@ export class Store {
3434
return systemPrefersDark;
3535
})();
3636

37+
constructor() {
38+
makeObservable(this, {
39+
allChunks: observable.ref,
40+
selectedChunks: observable.shallow,
41+
searchQuery: observable,
42+
defaultSize: observable,
43+
selectedSize: observable,
44+
showConcatenatedModulesContent: observable,
45+
darkMode: observable,
46+
47+
hasParsedSizes: computed,
48+
activeSize: computed,
49+
visibleChunks: computed,
50+
allChunksSelected: computed,
51+
totalChunksSize: computed,
52+
searchQueryRegexp: computed,
53+
isSearching: computed,
54+
foundModulesByChunk: computed,
55+
foundModules: computed,
56+
hasFoundModules: computed,
57+
hasConcatenatedModules: computed,
58+
foundModulesSize: computed,
59+
});
60+
}
61+
3762
setModules(modules) {
3863
walkModules(modules, (module) => {
3964
module.cid = this.cid++;
@@ -47,11 +72,11 @@ export class Store {
4772
this.entrypoints = entrypoints;
4873
}
4974

50-
@computed get hasParsedSizes() {
75+
get hasParsedSizes() {
5176
return this.allChunks.some(isChunkParsed);
5277
}
5378

54-
@computed get activeSize() {
79+
get activeSize() {
5580
const activeSize = this.selectedSize || this.defaultSize;
5681

5782
if (!this.hasParsedSizes || !this.sizes.has(activeSize)) {
@@ -61,26 +86,26 @@ export class Store {
6186
return activeSize;
6287
}
6388

64-
@computed get visibleChunks() {
89+
get visibleChunks() {
6590
const visibleChunks = this.allChunks.filter((chunk) =>
6691
this.selectedChunks.includes(chunk),
6792
);
6893

6994
return this.filterModulesForSize(visibleChunks, this.activeSize);
7095
}
7196

72-
@computed get allChunksSelected() {
97+
get allChunksSelected() {
7398
return this.visibleChunks.length === this.allChunks.length;
7499
}
75100

76-
@computed get totalChunksSize() {
101+
get totalChunksSize() {
77102
return this.allChunks.reduce(
78103
(totalSize, chunk) => totalSize + (chunk[this.activeSize] || 0),
79104
0,
80105
);
81106
}
82107

83-
@computed get searchQueryRegexp() {
108+
get searchQueryRegexp() {
84109
const query = this.searchQuery.trim();
85110

86111
if (!query) {
@@ -94,11 +119,11 @@ export class Store {
94119
}
95120
}
96121

97-
@computed get isSearching() {
122+
get isSearching() {
98123
return !!this.searchQueryRegexp;
99124
}
100125

101-
@computed get foundModulesByChunk() {
126+
get foundModulesByChunk() {
102127
if (!this.isSearching) {
103128
return [];
104129
}
@@ -155,18 +180,18 @@ export class Store {
155180
.sort((c1, c2) => c1.modules.length - c2.modules.length);
156181
}
157182

158-
@computed get foundModules() {
183+
get foundModules() {
159184
return this.foundModulesByChunk.reduce(
160185
(arr, chunk) => arr.concat(chunk.modules),
161186
[],
162187
);
163188
}
164189

165-
@computed get hasFoundModules() {
190+
get hasFoundModules() {
166191
return this.foundModules.length > 0;
167192
}
168193

169-
@computed get hasConcatenatedModules() {
194+
get hasConcatenatedModules() {
170195
let result = false;
171196

172197
walkModules(this.visibleChunks, (module) => {
@@ -179,7 +204,7 @@ export class Store {
179204
return result;
180205
}
181206

182-
@computed get foundModulesSize() {
207+
get foundModulesSize() {
183208
return this.foundModules.reduce(
184209
(summ, module) => summ + module[this.activeSize],
185210
0,

0 commit comments

Comments
 (0)