Skip to main content
Source Link
Lukas Lang
  • 34.7k
  • 1
  • 59
  • 99

ValueTrack`CollectTrackEvent

This helps with figuring out what caused a Dynamic to update:

a = 1;
f[x_] := a x^2
ValueTrack`CollectTrackEvent[True]

Dynamic[{ValueTrack`CollectTrackEvent[], f[2]}]
(* {{Hold[a, HoldComplete[a, 1, 2, OwnValues], {909089}]}, 8} *)

a = 2;

ValueTrack`CollectTrackEvent[False]

The functionality is enabled using ValueTrack`CollectTrackEvent[True] and disabled again using ValueTrack`CollectTrackEvent[False]. While it is enabled, ValueTrack`CollectTrackEvent[] will return a list of value changes that were tracked by some Dynamic (while disabled, it will return Null). Some notes:

  • ValueTrack`CollectTrackEvent[] will return the list of all value changes since the last time it was called. It does not matter which Dynamic was updated, you simply get one long list.

  • The format seems to be

    {{sym_, update_, {boxIDs__}}...}
    

    where sym is the symbol causing the update, update is a description of the update (which part was updated, old and new value, type of value). The format seems to be the same as for the "ValueChange" handler. Finally, boxIDs is a list of IDs of the DynamicBox expressions updated by that value change.

Credit goes to Kyle Martin (WRI) for showing this to me. - Thanks again!

There's also ValueTrack`GetTrackingState and ValueTrack`SetTrackingState, but I don't know what they do

Post Made Community Wiki by Lukas Lang