Design Patterns

JS – Adapting to the situation (smart coding) with Portlet’s

4

Preface

For the past few months I’ve been workin with a content management portal to deliver my XHTML/JS/CSS I can’t stress how big a pain in the arse this is, as with any CMS there are limitations in the way that it works and problems when you try to use it for more than what it’s really made for. Limitations of a CMS can include:

  1. not being able to add code/css to the header
  2. the CMS just spitting out any old JS/CSS in the HTML
  3. HTML not being formatted correctly, or just spitting out random XHTML tags

The list could go on, but I’m too tired to really carry on. It puts a big downer on you most of all when you’re so anal that all of your HTML is well formated and perfectly indented, only to find when the site goes live, all of your code is on one line or it looks like it’s been run over by a bus.

My main concern with coding for CMS’s that use portlet’s is the simple fact that each portlet is in essence it’s own self contained application/controller. It becomes a pain when you have to constantly check to see whethter a portlet exists in the DOM on runtime.

How can you work around this? Think like a CMS. You might be thinking, what the f**k is he talking about? The simple solution is to adapt the way you code to suit the CMS. Instead of having one big JS file for a page or site section, seperate your code into small chunks, this will also help you unit test your code which I’ll come to a bit later.

(more…)

{ Publisher Subscriber Pattern }

2

A few weeks ago I was introduced to the Publisher Subscriber pattern in JS, pretty much confused by the methodology behind it I decided to give it a go.

The publisher subscriber pattern allows several methods to subscribe to a particular event. Methods and functions can unsubscribe and subscribe to any event at will, this is handy if you want to remove or add a method to an event handler at runtime.
(more…)

Go to Top