Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default priority? How to set a listener to be called at the end? #43

Open
julkue opened this issue Jan 22, 2015 · 3 comments
Open

Default priority? How to set a listener to be called at the end? #43

julkue opened this issue Jan 22, 2015 · 3 comments

Comments

@julkue
Copy link

julkue commented Jan 22, 2015

Hi,

unfortunately I didn't found any deeper documentation about priority. The documentation says that there is a priority property and you can set a integer value but there is no example or use case.

However, I would like to begin with one use case. I have one function that should be called as the last event listener since it depends on settings the previous listeners will set. Therefore it would be good to know what the default priority is? If it would be 1 I hopefully could set priority to 0 and the function would be called at the end.

However, could somebody @ajacksified tell me how to manage such situations with Mediator.js?

@julkue
Copy link
Author

julkue commented Jan 22, 2015

Setting priority to 0 or e.g. -999 will not work

@ajacksified
Copy link
Owner

Correct; right now, it only changes current priority, there's no way to tell a function to always be called last; the only way to do it would be to add new listeners with a priority of 1 to that they're added later.

Do you have ideas on how you might want to work with the api to tell something to always be last?

@julkue
Copy link
Author

julkue commented Feb 10, 2015

@ajacksified This is how I solved the problem the other day: In the related app I created a requireJS module called "mediator". Every other module will require that module. It will add observers/listeners to that module so not directly to the mediatorJS plugin. So I can set a default priority of e.g. 10 if no priority was defined. So now I have to options: Define a priority or define no priority. If one is defined, then go ahaid. If no one is defined, it will define e.g. 10 so that there is enough space for e.g. 9 listeners with less priority (last-listeners).

To your question. IMHO it would be a mistake to add a option like "last" so that defined listeners will be called at the end. The question would be: how do you act if there are multiple listeners with that property? So my solution for your plugin would be to define a default (fallback) priority like 0 and allow minus e.g. -10 priority to set "last"-listeners.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants