1- import { observable , computed } from "mobx" ;
1+ import { observable , computed , makeObservable } from "mobx" ;
22import { isChunkParsed , walkModules } from "./utils" ;
33import 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