Javascript pub sub pattern


Keywords: pub sub, javascript, pub/sub, typescript, typescript generics
Publish Date: 9/22/2013
Description: javascript pub/sub pattern using typescript with generics

My team is using the pub sub pattern for a large one page app Point of Sale system at work. We started the app before generics were introduced into typescript so a few of us are pondering the ways we can benefit from strongly typed messages and or call backs within our pattern.

Working version: http://jsfiddle.net/TheDev6/LjuXu/

Some good reading.

http://msdn.microsoft.com/en-us/magazine/hh201955.aspx
http://addyosmani.com/largescalejavascript/

The HTML The Typescript The Javascript (rendered from typescript)

Comments (3):

Name: Allan Chadwick
Comment Date: 4/17/2014
Comment:
I'm happy to report that this made it into production on our Single Page App. It seems to have cleared up some code but there is still a long way to go. I wouldn't rest here though and be warned that type script can 'hide' the real nature of javascript. This simply enforces the proper use of a function where applicable.


Name: Michael
Comment Date: 5/15/2015
Comment:
Thanks for the pub/sub example. The one I'm currently using was extremely basic, and did not have type safety for the message being published/subscribed.


Name: Allan Chadwick
Comment Date: 5/29/2015
Comment:
I'm glad this code is useful! Be sure to also search for the latest pub sub libraries as well since it seems like a new one comes out every week that does something really cool.


Leave a Comment:




    Captcha Challenge