Decoupling data and UI layers with PubSub architecture
Written by on December 3rd, 2008 in Uncategorized.
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:
-
-
pubSubBroker.subscribe(‘email-open’, gData, ‘onRead’);
-
pubSubBroker.subscribe(‘email-open’, gUI, ‘markEmail’, true);
-
var email = {title:‘Test email’, id:1, body:‘Test body’};
-
//This will call both gData.onRead(email) and gUI.markEmail(true, email);
-
pubSubBroker.publish(‘email-arrive’, email);
-
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