11import { snapshot } from '../../shared/clone.js' ;
22import { STATE_SYMBOL } from '../constants.js' ;
33
4- /** @type { { label: string, time: number, sub: any, stack: string | void, value: any }[] | null } */
4+ export const NOT_REACTIVE = 0 ;
5+ export const REACTIVE_UNCHANGED = 1 ;
6+ export const REACTIVE_CHANGED = 2 ;
7+
8+ /** @type { { changed: boolean, label: string, time: number, sub: any, stack: string | void, value: any }[] | null } */
59export let tracing_expressions = null ;
6- export let tracing_expression_reactive = false ;
10+ /** @type { 0 | 1 | 2 } */
11+ export let tracing_expression_reactive = NOT_REACTIVE ;
712
813/**
914 * @param {any } expressions
@@ -13,18 +18,21 @@ function log_expressions(expressions) {
1318 const val = expression . value ;
1419 const label = expression . label ;
1520 const time = expression . time ;
21+ const changed = expression . changed ;
1622
1723 if ( time ) {
1824 // eslint-disable-next-line no-console
1925 console . groupCollapsed (
20- `${ label } %c${ time . toFixed ( 2 ) } ms` ,
26+ `%c${ label } %c${ time . toFixed ( 2 ) } ms` ,
27+ ! changed ? 'color: darkgrey; font-weight: normal' : undefined ,
2128 'color: grey' ,
2229 val && typeof val === 'object' && STATE_SYMBOL in val ? snapshot ( val , true ) : val
2330 ) ;
2431 } else {
2532 // eslint-disable-next-line no-console
2633 console . groupCollapsed (
27- label ,
34+ `%c${ label } ` ,
35+ ! changed ? 'color: darkgrey; font-weight: normal' : undefined ,
2836 val && typeof val === 'object' && STATE_SYMBOL in val ? snapshot ( val , true ) : val
2937 ) ;
3038 }
@@ -79,7 +87,7 @@ export function trace(fn, label, computed) {
7987 var previously_tracing_expression_reactive = tracing_expression_reactive ;
8088
8189 try {
82- tracing_expression_reactive = false ;
90+ tracing_expression_reactive = NOT_REACTIVE ;
8391 tracing_expressions = [ ] ;
8492 var value ,
8593 time = 0 ;
@@ -98,8 +106,15 @@ export function trace(fn, label, computed) {
98106 ?. split ( '\n' )
99107 [ / F i r e f o x / . test ( navigator . userAgent ) ? 3 : 2 ] . trimStart ( ) ;
100108
101- if ( tracing_expression_reactive ) {
102- tracing_expressions . push ( { label, value, time, stack, sub : null } ) ;
109+ if ( tracing_expression_reactive !== NOT_REACTIVE ) {
110+ tracing_expressions . push ( {
111+ changed : tracing_expression_reactive === REACTIVE_CHANGED ,
112+ label,
113+ value,
114+ time,
115+ stack,
116+ sub : null
117+ } ) ;
103118
104119 if ( previously_tracing_expressions !== null ) {
105120 previously_tracing_expressions . push ( ...tracing_expressions ) ;
@@ -109,6 +124,7 @@ export function trace(fn, label, computed) {
109124 previously_tracing_expressions . length !== 0
110125 ) {
111126 previously_tracing_expressions . push ( {
127+ changed : tracing_expressions . some ( e => e . changed ) ,
112128 label,
113129 value,
114130 time,
@@ -125,6 +141,9 @@ export function trace(fn, label, computed) {
125141 }
126142}
127143
128- export function tracing_reactive_signal ( ) {
129- tracing_expression_reactive = true ;
144+ /**
145+ * @param {0 | 1 | 2 } value
146+ */
147+ export function set_tracing_expression_reactive ( value ) {
148+ tracing_expression_reactive = value ;
130149}
0 commit comments