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 either publishEvent or postEvent will be able to help but the docs could be a bit more explicit?


  • admin

    see mojo.events.publishEvent

    publishEvent will post to the active tool and all observers.

    postEvent will 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 postEvent for you custom events. (use reversed domain name for the notification name)



  • @frederik ah, makes sense. thanks again!


  • admin

    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 publishEvent for known notifications.



  • Hi, I have a follow-up question to this thread.

    Right now I have a BaseEventTool tool that has a separate "settings" window. Like you mentioned above, the window runs postEvent whenever 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 use publishEvent, does the tool not need observers (ie. how does the tool know about this event)? Thanks!


  • admin

    see mojo.events.publishEvent

    publishEvent will post to the active tool and all observers.

    postEvent will 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 postEvent for you custom events. (use reversed domain name for the notification name)