JavaScript / Pub / Sub-Message Priorities

More discussion than question:

I read an article entitled "Templates for a Large-Scale JavaScript Application Architecture" and so far it has been pretty noticeable.

The author of this article advocates using the pub / sub architecture using a mediator / controller. There are no real examples, but on the slide show itself ( http://addyosmani.com/blog/jqcon-largescalejs-2012/ ) it protects the use of "Amplify.js".

As with many other pub / sub implementations, Amplify supports message prioritization. My understanding is that with an intermediary, the need to prioritize messages is reduced because the intermediary controls what happens, when and where. Is this a valid point?

Message priorities scare me, because when the application grows (and changes), you can get a bunch of modules, all with different priorities set on their subscriptions, and no real control over what happens. Is this a real concern or just a misunderstanding of how they should actually be used?

+7
source share
2 answers

I would caution against using any complex version of pub / sub. Instead of thinking in terms of priorities, thinking in terms of channels and assuming that all channels are processed independently of each other, and none of them has a "priority".

Another caveat: do not use module names as channel names or namespaces. If you do this, you can also provide other modules with a direct link to your module and calling methods directly. The thing is that your modules do not know about each other and do not report directly.

One more tip: do not tell other modules what to do. Instead, report events that occurred inside the module sending the message. This subtle shift in thinking is key to ensuring that the modules are untied.

+1
source

I found this use for pub / sub priorities useful, based on the good idea of ​​using them as "channels" as suggested on this subject.

Subscription Priorities, where 1 is the highest and 5 is the lowest:

  • Debug messages
  • Subscriptions with any changes to the DOM layout that affect the size or position of elements.
  • Subscriptions using only DOM style changes that do not affect the layout.
  • Subscriptions that read the layout or style in the DOM.
  • Subscriptions without touching the DOM (pure JS).

This should hopefully prevent as much layout as possible.

Sorry to reply to the old post, but on the first page in google for "pub sub priority", and there are not many.

+1
source

All Articles