@@ -16,9 +16,13 @@ function sleep(ms): Promise<void> {
16
16
}
17
17
18
18
function defaultUpdate ( previousEvent : Event , currentPayload : JSONEventPayload ) : JSONEventPayload {
19
+ const count = Number . isInteger ( previousEvent . payload . count ) ? previousEvent . payload . count as number : 1 ;
20
+
19
21
return {
20
22
...previousEvent . payload ,
21
23
...currentPayload ,
24
+ count : count + 1 ,
25
+ duration : Date . now ( ) - previousEvent . timestamp . getTime ( ) ,
22
26
} ;
23
27
}
24
28
@@ -29,19 +33,14 @@ interface IgnoreRule {
29
33
update : ( previousEvent : Event , currentPayload : JSONEventPayload ) => JSONEventPayload ;
30
34
}
31
35
32
- type IgnoredRules = (
33
- EventScope . zoomImage | EventScope . changeAttribute |
34
- EventScope . changeFrame | EventScope . exception
35
- ) ;
36
-
37
36
class Logger {
38
37
public clientID : string ;
39
38
public collection : Array < Event > ;
40
39
public lastSentEvent : Event | null ;
41
- public ignoreRules : Record < IgnoredRules , IgnoreRule > ;
40
+ public ignoreRules : Record < string , IgnoreRule > ;
42
41
public isActiveChecker : ( ) => boolean ;
43
42
public saving : boolean ;
44
- public compressedScopes : Array < IgnoredRules > ;
43
+ public compressedScopes : Array < EventScope > ;
45
44
46
45
constructor ( ) {
47
46
this . clientID = Date . now ( ) . toString ( ) . substr ( - 6 ) ;
@@ -54,6 +53,8 @@ class Logger {
54
53
[ EventScope . zoomImage ] : {
55
54
lastEvent : null ,
56
55
ignore : ( previousEvent : Event ) : boolean => {
56
+ // previous event from the same scope is the latest push event in the collection
57
+ // it means, no more events were pushed between the previous and this one
57
58
const [ lastCollectionEvent ] = this . collection . slice ( - 1 ) ;
58
59
return previousEvent === lastCollectionEvent ;
59
60
} ,
@@ -78,16 +79,6 @@ class Logger {
78
79
} ;
79
80
} ,
80
81
} ,
81
- [ EventScope . changeAttribute ] : {
82
- lastEvent : null ,
83
- ignore ( previousEvent : Event , currentPayload : JSONEventPayload ) : boolean {
84
- return (
85
- currentPayload . object_id === previousEvent . payload . object_id &&
86
- currentPayload . id === previousEvent . payload . id
87
- ) ;
88
- } ,
89
- update : defaultUpdate ,
90
- } ,
91
82
[ EventScope . changeFrame ] : {
92
83
lastEvent : null ,
93
84
ignore ( previousEvent : Event , currentPayload : JSONEventPayload ) : boolean {
@@ -168,7 +159,7 @@ Object.defineProperties(Logger.prototype.log, {
168
159
}
169
160
170
161
if ( scope in this . ignoreRules ) {
171
- const ignoreRule = this . ignoreRules [ scope as IgnoredRules ] ;
162
+ const ignoreRule = this . ignoreRules [ scope ] ;
172
163
const { lastEvent } = ignoreRule ;
173
164
if ( lastEvent && ignoreRule . ignore ( lastEvent , payload ) ) {
174
165
lastEvent . payload = ignoreRule . update ( lastEvent , payload ) ;
@@ -189,7 +180,7 @@ Object.defineProperties(Logger.prototype.log, {
189
180
this . collection . push ( event ) ;
190
181
191
182
if ( scope in this . ignoreRules ) {
192
- this . ignoreRules [ scope as IgnoredRules ] . lastEvent = event ;
183
+ this . ignoreRules [ scope ] . lastEvent = event ;
193
184
}
194
185
} ;
195
186
0 commit comments