1
- import { ApplyPath , CallType , InterfaceType , NodeName , PlatformInstanceId } from './types' ;
1
+ import {
2
+ ApplyPath ,
3
+ CallType ,
4
+ InstanceId ,
5
+ InterfaceType ,
6
+ NodeName ,
7
+ PlatformInstanceId ,
8
+ WinId ,
9
+ } from './types' ;
2
10
import {
3
11
ApplyPathKey ,
4
12
InstanceDataKey ,
@@ -18,7 +26,7 @@ export const logMain = (msg: string) => {
18
26
}
19
27
} ;
20
28
21
- export const logWorker = ( msg : string , winId = - 1 ) => {
29
+ export const logWorker = ( msg : string , winId ?: WinId ) => {
22
30
if ( debug ) {
23
31
try {
24
32
const config = webWorkerCtx . $config$ ;
@@ -31,7 +39,7 @@ export const logWorker = (msg: string, winId = -1) => {
31
39
32
40
let prefix : string ;
33
41
let color : string ;
34
- if ( winId > - 1 ) {
42
+ if ( winId ) {
35
43
prefix = `Worker (${ normalizedWinId ( winId ) } ) 🎉` ;
36
44
color = winColor ( winId ) ;
37
45
} else {
@@ -51,15 +59,15 @@ export const logWorker = (msg: string, winId = -1) => {
51
59
}
52
60
} ;
53
61
54
- const winIds : number [ ] = [ ] ;
55
- export const normalizedWinId = ( winId : number ) => {
62
+ const winIds : WinId [ ] = [ ] ;
63
+ export const normalizedWinId = ( winId : WinId ) => {
56
64
if ( ! winIds . includes ( winId ) ) {
57
65
winIds . push ( winId ) ;
58
66
}
59
67
return winIds . indexOf ( winId ) + 1 ;
60
68
} ;
61
69
62
- const winColor = ( winId : number ) => {
70
+ const winColor = ( winId : WinId ) => {
63
71
const colors = [ '#00309e' , '#ea3655' , '#eea727' ] ;
64
72
const index = normalizedWinId ( winId ) - 1 ;
65
73
return colors [ index ] || colors [ colors . length - 1 ] ;
@@ -212,8 +220,8 @@ const getLogValue = (applyPath: ApplyPath, v: any): string => {
212
220
return `[${ v . map ( getLogValue ) . join ( ', ' ) } ]` ;
213
221
}
214
222
if ( type === 'object' ) {
215
- const instanceId : number = v [ InstanceIdKey ] ;
216
- if ( typeof instanceId === 'number ' ) {
223
+ const instanceId : InstanceId = v [ InstanceIdKey ] ;
224
+ if ( typeof instanceId === 'string ' ) {
217
225
if ( instanceId === PlatformInstanceId . body ) {
218
226
return `<body>` ;
219
227
}
0 commit comments