The notification order of ValueTree::Listeners

Hi everybody!

Will the first ValueTree::Listener added to the valueTree listener list always be the first one being notified about any changes? For example, if I have code like:

valueTree.addListener (listenerA);
valueTree.addListener (listenerB);

When I call

valueTree.addChild (child,…);

Will the function valueTreeChildAdded in listenerA always be called before listenerB?

The API gives no guarantee for that.
Currently the listeners are implemented as ListenerList (with a juce::Array underlying), so the answer is yes, but you shouldn’t rely on that. There might happen things now or in future that can change that (e.g. adding a listener checks if already present, so if the listener was already added before it won’t move that to the last)

1 Like

We ran into this problem recently - listeners are actually called in reverse order:

I believe the reason is to handle cases where a listener might be added or removed while the callback is happening.

1 Like

Good catch, thanks for the correction @ImJimmi

1 Like