Broadcaster does not send signal when using declared objects.
-
Hey,
is this a bug or a feature? When defining a object and assigning it to a broadcaster, it only sends a signal once. Every further update results in no signals being send. It seems like the Object id stays the same since we are technically still using the same Object so it does not register as a valid change.Content.makeFrontInterface(600, 600); var STATE = { 'Playlist' : 'Playlist1' }; const var b = Engine.createBroadcaster({ "id": "My Broadcaster", "args": ["state"] }); b.addListener({"id": "Listener"}, "Listening...", function(state) { Console.print('receiving signal'); Console.print(trace(state)); }); b.state = STATE; Console.print('updating state'); STATE['Property'] = {another: 'one'}; Console.print(trace(STATE)); b.state = STATE; Console.print('Broadcaster does not send out signal');
HiseSnippet 853.3ocsUstZZDDEdVianZuPCzGfA+iFvJZaZZIkRS7RJRiIR0FJDBgwYG0grNyxLylVo36PeT6aP6Y1c8RLhMQn6ODO2+lyb9NSakjxzZoB4jo63.Fx4ItcFKLCqMjvEnl0QNOysEQaXJbrppiCHZMyC43r0mrJbxjFE886OVk3SDT1bUHz4RNkcBeD2LWa6C+L22+XhGqKezBdu2gMoRQMouLDvyVtkQAD50jArSIV2R4hb1tgG2HUcLDCSC9TU5MtyP42Ew9eNWy64yrBUPcfDEqFUaH22q8zypFgbR2d9Ieq3S9Kbaw83yzOuC77HC34QrXOvI05fTkG.jbV.RoigzNtcnJdfYtEKddraSAbgzm.s5EgRrunT+JkaMI3gvTZD4Z1wJPXVDE1ub4hX3mcee1r2PT3NcOpaC7Gv+Lal7s8Ii84ZSd7A3YBUxmcB3Kb0nMXaD8.uaHFvErRTECN1UURhGMZJo.jlbbubGfy0ZLdAC4JBFHpAZvzE4z1tUtKyNwhhdkHddm.UhIrIHI7oJxMo3TAtXPoRkfL0OTPMbonPTd1MKTT3Dqk9rRAJtvTHuhQY7af.vZ9.AwOOTnk7wnrsi3L.VSfRjLb.iZKflkxaXfGwDkVqe1rF43E4gqn.lxLN+k1dIQHMCYJnKJEr7P6aUkNJRaouSUWpnKzFwdRlFCYGqYBOrLzL+.NsqfkhSkF1YhBQclrSxhW1T+9qzlcrQI88gqgUY1RWUqKvBhvQ8XphvXheHaliv77sIIae+HIz3o3EbTJZJ3lyBXIxGK88rC+1+eWJEJgF.+6qMqSLDKKKQWx8E2BGm5raf0TwbtLt0Y5qMx.XQ0cHjvp.oWnOwb68C1EgIFf9wsHkVhmPyMiWbQ4CXoQ40tz39BwcbayMzgqFioVAFgN0+CLlrp8otM52mQMyAXZ2i+1ltW8eT9u.jDfw1hXT7efbbOMbTG3EFJCptPv7gj65jxNsDKW1Ja6.c.FVjvefuDiUrxNIFqL0HZDgpjWQiYA1k4OJRCfIQzaWYfGQAYbETDy.hysboxnQv6JWQo1i+KgA3UGyq1fXd8FDydaPLuYChY+MHl2tAw7t0Fi8I8iBMxQwzAPQ6FQqHbbZHHvjUzTH5u.KbEiQC
-
@oskarsh Yes that's actually intended behaviour - a broadcaster is supposed to filter out repetitions of the same message so that it saves execution time. It uses a default JS comparison, so if you have an object as message it will not send the message because it still points to the same object (as you have assumed).
There are three options:
- Don't use a single object but multiple parameters by giving the
args
an array with multiple IDs. This way it will make sure to send the message when one of the properties change, but it only works if you know how many properties your object will have. From a clean code perspective this is the preferred option - You can explicitly tell the Broadcaster to not filter out repetitions (
setEnableQueue(true)
). This is required for some scenarios (eg. if a broadcaster listens to multiple sources) and in your case it brute-forces the broadcaster to behave like you want. - If you want to manually resend the message, you can use
resendLastMessage()
instead of assigning the object again, this will send the message no matter whether it changed or not.
- Don't use a single object but multiple parameters by giving the
-
@Christoph-Hart Thanks I ended up creating a new copy of the object which I then mutate. This is actually best practice in terms of state management. I then assign this newState to my broadcaster and update the actual state object.
-
@oskarsh ah yeah, that's the fourth option :)