7

I've been trying to use $.subscribe but it doesn't seem to work. I downloaded a WAR project where it does work but when I use this function in my project it doesn't work. Do I have to download an extra plugin?

Because I couldn't find info about these functions in the jQuery website either, I just found the new $.Callbacks() function. The reason I need to use $.subscribe is so I can use something like onBeforeTopic.

Thanks in advance.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Diego Ramos
  • 989
  • 4
  • 16
  • 35

2 Answers2

7

You will need Publish/subscribe plugin.

I stand corrected: you will need Struts2 jQuery Plugin.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Bart Platak
  • 4,387
  • 5
  • 27
  • 47
  • I'm using struts2-jquery-plugin and I've been able to use everything just fine, except this $.subscribe function, I don't know why, should they be included in this struts2 plugin? – Diego Ramos Aug 12 '12 at 01:47
  • 2
    According to [the documentation](http://code.google.com/p/struts2-jquery-plugin/#Publish/Subscribe_Framework), struts2-jquery-plugin uses publish/subscribe and should therefore include `$.subscribe` on it's own. It could be an issue with order in which you include scripts; i.e. you're trying to use `$.subscribe` before you loaded your plugin. Post your (relevant) code, in your original question so we can figure out what's going wrong :) – Bart Platak Aug 12 '12 at 01:52
  • +1. As an additional information: since [version 1.5.0](http://code.google.com/p/struts2-jquery/wiki/Changelog#1.5.0) Struts2 jQuery plugin uses the lightweight publish/subscribe framework made by Eric Chijioke, once was hosted on the jQuery plugin page, but since the end of 2011 is not available (still one can check the [original plugin page](https://web.archive.org/web/20111030003248/http://plugins.jquery.com/project/jQuerySubscribe) using Wayback Machine. Note: the archived pages usually load slow). – informatik01 Feb 12 '14 at 08:27
  • **Important note**: the up-to-date Struts2 jQuery plugin site is hosted as a project on Google Code, and the project name is [**struts2-jquery**](http://code.google.com/p/struts2-jquery/). Another one (last update 2010), also hosted on Google Code, has its project name confusingly named [**struts2-jquery-plugin**](http://code.google.com/p/struts2-jquery-plugin/), which seems to be the original development... – informatik01 Feb 12 '14 at 11:37
0

I know I'm a bit late to the party but why not just write your own simple pubsub? Check out this article: https://lowbrowcoder.wordpress.com/2015/02/16/pubsub-pattern-in-javascript/

Jake
  • 81
  • 1
  • 10
onetwopunch
  • 3,279
  • 2
  • 29
  • 44
  • Link is broken. But any search on this patern will give simples implementations, though I think it's better to write your own too. – Al Foиce ѫ Apr 13 '16 at 11:45