1
+ import { unwrapStore } from '@builder.io/qwik' ;
1
2
import type { ReplResult , ReplStore } from '../types' ;
2
3
3
- // TODO fix useStore to recursively notify subscribers
4
+ // Maybe we should change useStore to recursively notify subscribers when a top-level property changes
4
5
const deepUpdate = ( prev : any , next : any ) => {
5
6
for ( const key in next ) {
6
7
if ( prev [ key ] && typeof next [ key ] === 'object' && typeof prev [ key ] === 'object' ) {
7
8
deepUpdate ( prev [ key ] , next [ key ] ) ;
8
9
} else {
9
- if ( prev [ key ] !== next [ key ] ) {
10
+ if ( unwrapStore ( prev [ key ] ) !== next [ key ] ) {
10
11
prev [ key ] = next [ key ] ;
11
12
}
12
13
}
13
14
}
14
15
if ( Array . isArray ( prev ) ) {
15
- for ( const item of prev ) {
16
- if ( ! next . includes ( item ) ) {
17
- prev . splice ( prev . indexOf ( item ) , 1 ) ;
18
- }
16
+ if ( prev . length !== next . length ) {
17
+ prev . length = next . length ;
19
18
}
20
19
} else {
21
20
for ( const key in prev ) {
@@ -28,14 +27,6 @@ const deepUpdate = (prev: any, next: any) => {
28
27
29
28
export const updateReplOutput = async ( store : ReplStore , result : ReplResult ) => {
30
29
deepUpdate ( store . diagnostics , result . diagnostics ) ;
31
-
32
- if ( result . diagnostics . length === 0 ) {
33
- if ( result . html && store . html !== result . html ) {
34
- store . html = result . html ;
35
- store . reload ++ ;
36
- }
37
- }
38
-
39
30
deepUpdate ( store . transformedModules , result . transformedModules ) ;
40
31
deepUpdate ( store . clientBundles , result . clientBundles ) ;
41
32
deepUpdate ( store . ssrModules , result . ssrModules ) ;
@@ -47,6 +38,13 @@ export const updateReplOutput = async (store: ReplStore, result: ReplResult) =>
47
38
store . events = result . events ;
48
39
}
49
40
41
+ if ( result . diagnostics . length === 0 ) {
42
+ if ( result . html && store . html !== result . html ) {
43
+ store . html = result . html ;
44
+ store . reload ++ ;
45
+ }
46
+ }
47
+
50
48
if ( store . selectedOutputPanel === 'diagnostics' && store . monacoDiagnostics . length === 0 ) {
51
49
store . selectedOutputPanel = 'app' ;
52
50
}
0 commit comments