Custom Global Events / Variable Change Listeners

Don Pedro shared this question 4 years ago
Answered

I want to create custom interaction triggers / event listeners via e.g. a plugin.


My use case is that I want to be able to dispatch a custom event / set a variable on user interaction, and then listen in other parts of the prototype for this event / change to variable.


My current need is to have elements in one master (menu) interact with other masters, more specifically I wanted to have a menu item in my "menu" master dispatch an event/set a variable instead of directly manipulating the prototype (which it currently cant because the master has no knowledge of the surrounding context/parent), and then in the rest of my prototype I would be able to use the event as a trigger to show/hide layers.


Now, how is this best achieved ?

Comments (4)

photo
1

There is another request from some time ago about adding an option to listen to changes in a variable. Would that work for you too?

photo
1

thanks for responding so quickly !


Yes, having a trigger attached to the change of the value (literal or by reference) would work for me... lets imagine we have a variable that would be "visibleState", and we can toggle between "expanded" and "collapsed", and we could trigger changes to the displayed layer by switching the variable... maybe even more elaborate it would be to switch between a set of options.

photo
1

We'll add that information to our internal issue tracking.

photo
1

I would also appreciate a listener, like an event "if variable is changed to: X, then do something"