Marcus Westin (who we featured on finger print) gave a talk at the SF JavaScript meetup on a top that is very interesting:

One common issue in my experience are intricate dependencies between the UI and data models. Decoupling these is a huge benefit with respect to maintainability. The PubSub model is a great way to do it!

I’ve got a brief post along with a demo and sample code for a really compact PubSub tool, as well as a short discussion on the somewhat non-trivial javascript that makes it work with minimal code.

The demo app uses code such as:

JAVASCRIPT:

  1.  
  2. pubSubBroker.subscribe(‘email-open’, gData, ‘onRead’);
  3. pubSubBroker.subscribe(‘email-open’, gUI, ‘markEmail’, true);
  4. var email = {title:‘Test email’, id:1, body:‘Test body’};
  5. //This will call both gData.onRead(email) and gUI.markEmail(true, email);
  6. pubSubBroker.publish(‘email-arrive’, email);
  7.  

Marcus then goes through the PubSubBroker code itself.

I am a big fan of pubsub app development. I have talked about this wrt custom events in the past.

Source: Ajaxian » Front Page
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/473496056/decoupling-data-and-ui-layers-with-pubsub-architecture

Comments are closed.



Site Navigation