JZ Publish/Subscribe Updated to 1.4

One of the projects here on Joe Zim’s JavaScript blog is a Pub/Sub jQuery plugin that allows you to do the simple and generic subscribe, unsubscribe, and publish capabilities that you already find in jQuery (through on/bind, off/unbind, and trigger) but without all the extra overhead that jQuery has. JZ Publish/Subscribe has been updated to 1.4 and features a simple bug fix. You can also read about what to expect in 2.0, but I wouldn’t hold my breath for it.

What’s new?

In 1.3, I created a system that prevents some problems that may arise during publishing. Previously, if publish executed a function that would create a subscription to or unsubscribe from the list that was currently being published to, it could cause an error or unexpected behavior. 1.3 fixed this by creating a status that was used to delay unsubscribing until publishing was finished.

That solution had 2 problems:

  1. I forgot to implement it for subscribing. It was only set up to work for unsubscribing.
  2. It was way more complicate than it needed to be.

Since then I’ve come up with a much simpler solution: copy the list being published to. This removes the list from the ability to be edited by subscribe or unsubscribe, so no changes will affect what gets published to until the next time publish is called.

Looking Ahead

The next version of JZ Publish/Subscribe will receive a new feature: prioritization. I feel this feature is big enough to warrant a more substantial version number change, so it’ll be dubbed 2.0. I know this feature is used pretty rarely (but then again, so is this plugin), but there might be a few people who would really like it.

If you’re not sure what prioritization is, let me explain. When subscribing, you can specify an integer between 1 and 5 (3 would be default if none is supplied). When publishing, it’ll go through the priority numbers in order and publish to the subscriptions with priority 1 first, then priority 2, and so on. This way, even if you’re adding the subscription after many other subscriptions have been added, you can still make sure that subscription is published to before the others, unless all of the other subscriptions were also priority 1. This can be handy when one subscriber is dependent upon the computation done by a different subscriber.


I hope that the previous bugs haven’t been plaguing users of this plugin. I’ve rarely seen any application where that situation would arise, but it’s bound to happen somewhere. When it comes to updating to version 2, you might have to wait a while. As I mentioned, I don’t see many people looking for this feature, so this update is not high on my priority list. However, if I receive some comments to this post that tell me otherwise, I’ll bump up the priority on it. As always, God bless and happy coding!

Author: Joe Zimmerman

Author: Joe Zimmerman Joe Zimmerman has been doing web development ever since he found an HTML book on his dad's shelf when he was 12. Since then, JavaScript has grown in popularity and he has become passionate about it. He also loves to teach others though his blog and other popular blogs. When he's not writing code, he's spending time with his wife and children and leading them in God's Word.