@@ -57,14 +57,16 @@ export default class Live {
5757 /** Model of the lines of output */
5858 private readonly events = new Heap < Event > ( ( a , b ) => {
5959 if ( a . line === b . line ) {
60- return a . timestamp - b . timestamp
60+ // later timestamps get higher priority
61+ return b . timestamp - a . timestamp
6162 }
6263
6364 const stateDiff = a . stateRank - b . stateRank
6465 if ( stateDiff !== 0 ) {
6566 return stateDiff
6667 } else {
67- return a . timestamp - b . timestamp
68+ // later timestamps get higher priority
69+ return b . timestamp - a . timestamp
6870 }
6971 } )
7072
@@ -83,6 +85,7 @@ export default class Live {
8385 if ( tail . kind === "logs" ) {
8486 // handle a log line
8587 this . pushLineAndPublish ( stripColors ( data ) , cb )
88+ return
8689 }
8790
8891 // otherwise, treat it as an event
@@ -129,11 +132,7 @@ export default class Live {
129132 return
130133 }
131134
132- // inform the UI that we have updates
133- cb ( {
134- events : this . pushEvent ( data , metric , timestamp ) ,
135- workers : Object . values ( this . workers ) ,
136- } )
135+ this . pushEvent ( data , metric , timestamp )
137136 }
138137
139138 if ( name === "*" ) {
@@ -143,6 +142,12 @@ export default class Live {
143142 // this event affects a specific worker
144143 update ( name )
145144 }
145+
146+ // inform the UI that we have updates
147+ cb ( {
148+ events : this . importantEvents ( ) ,
149+ workers : Object . values ( this . workers ) ,
150+ } )
146151 }
147152 }
148153 } )
@@ -153,10 +158,14 @@ export default class Live {
153158
154159 /** @return the most important events, to be shown in the UI */
155160 private importantEvents ( ) {
156- return this . events
157- . toArray ( )
158- . slice ( 0 , this . opts . events || 8 )
159- . sort ( ( a , b ) => a . timestamp - b . timestamp )
161+ if ( this . opts . events === 0 ) {
162+ return [ ]
163+ } else {
164+ return this . events
165+ . toArray ( )
166+ . slice ( 0 , this . opts . events || 8 ) // 8 highest priority
167+ . sort ( ( a , b ) => a . timestamp - b . timestamp ) // sorted by time
168+ }
160169 }
161170
162171 /** Replace any timestamps with a placeholder, so that the UI can use a "5m ago" style */
@@ -182,6 +191,7 @@ export default class Live {
182191 }
183192
184193 private readonly lookup : Record < string , Event > = { }
194+
185195 /** Add `line` to our heap `this.events` */
186196 private pushEvent ( line : string , metric : WorkerState , timestamp : number ) {
187197 const key = this . prepareLineForUI ( line )
@@ -207,11 +217,11 @@ export default class Live {
207217 }
208218 }
209219
210- if ( this . opts . events === 0 ) {
220+ /* if (this.opts.events === 0) {
211221 return []
212222 } else {
213223 return this.importantEvents()
214- }
224+ } */
215225 }
216226
217227 /** This helps us parse out a [W5] style prefix for loglines, so we can intuit the worker id of the log line */
0 commit comments