blog tag

Javascript pub sub pattern

Description: javascript pub/sub pattern using typescript with generics
Publish Date: 09/22/2013
Keywords: pub sub javascript pub/sub typescript typescript 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
Allan Chadwick (04/17/2014)

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.


Michael (05/15/2015)

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.


Allan Chadwick (05/29/2015)

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.


© Chadwick 2021