Over a year and a half ago I started a project tentatively named “jHooks”. It was supposed to be a very plain Javascript plugin that would allow your applications to implement a light messaging service similar to event binding and triggering. This is also, now, frequently referenced as “Pub/Sub” (Publish / Subscribe). I actually worked really hard to try and figure out the best way to implement such “Javascript Web Hooks” (the term I was using to reference this method at the time).

On and off, over the span of 3 or 4 months, I pondered the best way to create such a, library agnostic, plugin. All that time, all that planning, down the drain as soon as I realized the much simpler solution right before my eyes, pubsub. Paul Irish had been the one to steer me away from the idea of “hooks” and shed some light on this pubsub magic. Alex Sexton & Rebecca Murphey would be two of the many Javascript developers that began to push this kind of loose coupling thinking for their Application architecture around that same time. People like Peter Higgins would then go on to write very elegant implementations, to which I still use today. As you can tell, I was not alone at this point.

So what does this tell me? Well, I had spent all this time thinking I was ahead of the curve when really there where others seeking out the same kind of functionality with much better insight into the proper implementation and mechanics. Should I be upset? No. Should I be discouraged? Of course not. Although my plugin was a failure, it was an attempt. I had made a conscious effort not to share my idea for months when I could have been apart of that bleeding-edge conversation. That said, the solution I was presented with was just what I was looking for, whether or not I had made it myself or been a contributor (which is often something hard for me to wrap my head around, if you know me well).

Stepping back and admitting defeat can be very hard sometimes. The more attached you are to an idea or solution the more stubborn you are to think subjectively compared to objectively. Having a good understanding of when to give up is extremely important and a valuable character trait. Failure can, ultimately, be flattering.

R.I.P “jHooks

I should note that jHooks was also supposed to run the bound methods synchronously. This was one of the key problems I was trying to solve but which I ultimately gave up on (there are still talks on how this could be accomplished in different Javascript circles). There is a possibility that you could queue / dequeue methods but that would require all functions dequeuing themselves or else the chain will break, not ideal.

tags: / / /

2 comments

  • Addy Osmani

    Posted: Jun 8, 2011

    I think it’s really interesting that during our careers we come across several problems to which we think there *has* to be a better solution and then discover one day that there’s something out there that already helps us do exactly what we want. It’s like an ‘aha!’ moment of glory..until we realize we have to scrap what we’ve already created :)

    I’m sure you learned some lessons during the development of jHooks though.

    PS: Although pubsub has been popularized in the JavaScript community over the past year, it’s actually existed for a quite a long time (in both JS and other programming paradigms) under the name of the observer pattern (which exists to encourage loose coupling as a part of its design) :)

  • darcyclarke

    Posted: Jun 8, 2011

    You’re right about pubsub Addy, I should have said something to the effect of it not being new to programming but was net new to me. Not coming from a Comp Sci background, I find that there are a few holes within my knowledge base, and pubsub was one of those. Looking forward to even more of those “aha!” moments :)

"w3fools.com - because friends don't let friends use w3schools" ~ dan heberden
themify
Learning JavaScript