message queue for jquery
I've I have a site where I need to refresh several parts of the site when an event occurs. For example I add a task to a todo list I need to refresh the todo-list and perhaps a 开发者_如何学Pythonsummary and what not.
I don't want to couple the parts of the site with each other, since that would cause a giant sticky piece of mud code.
The approach I'm considering right now is to have a message queue where I can send events too and the all functions subscribing to the event will be executed.
Is there a plugin that has a message queue like this already? Do I need to implement one on my own?
Is there a better way to solve this problem without using a plugin?
You could use a pushlish/subscribe pattern. Every time an event is triggered, it will publish information out to any widget on the page that has subscribed to that event. That way you don't couple the event trigger to the display. See the example below.
http://darcyclarke.me/development/library-agnostic-pubsub-publish-subscribe/
Or you could use something like pubsubjs. https://github.com/mroderick/PubSubJS
You could make use of the JavaScript arrays and the push()
and pop()
functions, where a successful event-call would pop()
an event off of the stack using a callback method.
精彩评论