PubSub, Evented Programming and Javascript « Thomas Reynolds
Edit
I was having a headache working with javascript. I was yelling at the messy-ness of the code I have written thanks to the async nature of a javascript api I was using. After a whole day trying my best passing callback to the async method which is 2 levels underneath. Then, suddenly I realized that why don't I use the pub sub pattern to handle it. It greatly decouple the logic of my code. It is not that I haven't use it before, but when you don't use it for sometime you will forget its' existence. I will try to use the pub sub pattern everytime I do an async call in javascript! Here are some sample code of how it could implemented in jQuery PubSub, Evented Programming and Javascript « Thomas Reynolds
After solving that question, another questions comes to my mind, should I implement the pattern myself or use a plugin written by others? If I were doing a normal desktop web app, I would definitely find a plugin and use it, but this time my target device is a mobile device, the jQuery lib alone is big enough, I might just implement my own with jQuery this time. After all, it is not that hard to implement.
[Edited] After facing an algorithm design problem again, I have look at other implementation of PubSub in javascript and found this post in github https://gist.github.com/1321768 , it has 4 implementation and I picked the last one as it look most efficient.
[Edited] After facing an algorithm design problem again, I have look at other implementation of PubSub in javascript and found this post in github https://gist.github.com/1321768 , it has 4 implementation and I picked the last one as it look most efficient.
PubSub, Evented Programming and Javascript « Thomas Reynolds
Reviewed by DF
on
6:56:00 PM
Rating: