SOLVED Difference between mojo.events.publishEvent and mojo.events. postEvent
-
I want to a tool, subclassed from
BaseEventTool, to generate my own events that a different window can respond to. I'm guessing eitherpublishEventorpostEventwill be able to help but the docs could be a bit more explicit?
-
publishEventwill post to the active tool and all observers.postEventwill just post the notification to all observers and not to the active tool.The difference is the order, the active tool get all the notifications first, before any observer. Depending on the goal you mostly only need
postEventfor you custom events. (use reversed domain name for the notification name)
-
@frederik ah, makes sense. thanks again!
-
if you are sending a custom notification, then you should just use
postEvent– so no tool other than your own will be able to listen.Use
publishEventfor known notifications.
-
Hi, I have a follow-up question to this thread.
Right now I have a
BaseEventTooltool that has a separate "settings" window. Like you mentioned above, the window runspostEventwhenever its settings have been updated, and the tool has an observer to watch for the event.In this case, is it better to use
publishEvent? If I usepublishEvent, does the tool not need observers (ie. how does the tool know about this event)? Thanks!
-
publishEventwill post to the active tool and all observers.postEventwill just post the notification to all observers and not to the active tool.The difference is the order, the active tool get all the notifications first, before any observer. Depending on the goal you mostly only need
postEventfor you custom events. (use reversed domain name for the notification name)