Event handling libraries for javascript

published Oct 13, 2013 03:20   by admin ( last modified Oct 14, 2013 02:49 )

I'm thinking of adding some levels and achievements to a javascript based game. Since the points scoring is already there, it would be really nice if I could just have the scoring emit some kind of event that can be caught by the level and achievements code. In this way there would be a reasonably clean and simple interface between the code sections.

 

So I went to the Microjs site and found a dozen or so libraries that handled events. They seemed to fall into three categories:

  1. Libraries only interested in the DOM. I wanted something a bit more abstract, decoupled from the DOM.
  2. Libraries that modify the objects they are operating on. This seemed to me to not be very transparent, and I would need to come up with objects. Since it is a mobile application I need to persist stuff through the create/pause/resume/destroy lifecycle, and i do not want to end up with some objects - that have data that is persisted - also have some state related to what events they emit or listen to, while others objects may be loaded from script with no memory of this
  3. So, the third group uses a dedicated central object, that just emits nice clean text messages. These libraries seem to be classified as doing the pubsub pattern or mediator pattern. This I believe is what I want.

 

Candidates in group 3 so far are:

A light utility class to help implement the Mediator pattern


Read more: Link - Mediator.js