Friday, September 30, 2011


Thank you, thank you.  This is a very succinct description of how to do OOP with javascript.  It is exactly what I was looking for with really good examples and not much to read through.

Thursday, September 29, 2011

Dojo.stopEvent didn't work due to exception

function connectGenerateChartButton() {
	var buttonNode = dojo.byId("generateChartButton");
	dojo.connect(buttonNode, "onclick", function(evt) {
		console.log("Stop this event from doing a form submit.");
		console.log("Publish event for the generate chart button.");
		dojo.publish("generateChart", ["Woohoo!"]);

    dojo.subscribe("generateChart", function(text){
I am using pub/sub so I can be in a position to unit test my event code.  (I'm decoupling the UI event and the actual business logic.)  I ran into an issue with dojo.stopEvent as shown above.  Originally I had the stopEvent and publish lines switched so I would publish first and then stop the event.  Seems logical right?  I found out that my generateChart function had an exception that propagated out to my onclick handler and my stopEvent code was being skipped because of the exception.  I was getting a post anyway!

So for now I moved my stopEvent to be the first thing in this anon function.  That might be best practice anyway.

Also I need to learn more about exception handling.  I have a try/catch in my "main" function, but maybe that is not enough.

Wednesday, September 28, 2011

Closures in Javascript

So I never really understood closures or what they were for. This is a great reference explaining closures.

There is a link near the bottom that explains how to use closures for private members. Also closures can be used for callback methods.

Dojo charting bug

So I think I found a dojo bug today.  I have a chart that I am specifying the size with CSS.  It was working great.  Then I put the chart inside a TabContainer.  If the ContentPane is not selected, the chart will render with the default size of 400 x 300.  This is because the ContentPane with the chart is initially not visible.

I say I *think* I found a bug because I can understand why the size is defaulted.  Dojo would have to somehow render an invisible page to it could check the CSS and parent CSS to get the sizes, margins, offsets, etc. of all of the page elements of an invisible page, just to get the size of the chart correct.

Tuesday, September 27, 2011

Why use a Javascript Framework?

Why use a Javascript Framework?  There are several reasons.

  1. The framework will account for different browsers (IE, Firefox, Chrome, Safari).
  2. It may account for different devices (PC, tablet, smart phone).
  3. It will account for different browser versions.  For example, older browsers will not support HTML5.  A framework should have a fall back option.
  4. It helps with separation of concerns.  Any good framework will have a DOM query option so you can apply javascript functions to any DOM node.
  5. I'm sure there are other reasons, so I'll come back later and update this more.

Thursday, September 22, 2011

Javascript functions and OOP

This is really a must read about javascript functions and Object Oriented Programming.  I was just looking for the syntax of "call" and I got more than I bargained for, but that's good!  I agree with the writer, it's too easy to declare global functions (or functions on the outermost object - window in most cases).

Laptop Cup Holder

My laptop must think I'm thirsty.  The cup holder keeps popping out.  ;)

Wednesday, September 21, 2011

Chart Data Progress

OK, so I abandoned the DataSeries dojo object.  It was not very well documented and failing all the time.  So I did this, which I am pretty pumped about:

testData2 = [
{ name: "Development",
data: [1000,1000,1000,1000,1000,1000,1000,1000] },
{ name: "Test Site 1",
data: [1000,1100,1200,1300,1400,1500,1600,1700] },
{ name: "Product  #1",
data: [1000,1200,1500,4000,4000,4000,4000,4000] },
{ name: "Test Site 2",
data: [5000,3000,0,0,0,0,0,0] },

        // Other code omitted.

dojo.forEach( testData2, function(row,index){
}); is not a implementation

How many times can I shoot myself in the foot?  I was hoping that I could use the object to store data in memory in my application and pass it to a dojox.charting.DataSeries.  That does not work.  You get an error something like, getFeatures is not a function.  And indeed it isn't.  Memory does not have a getFeatures function.  On further review, if you look at the documentation for KeyValueStore, you see that it says it is an implementation of  Seeing that Memory is in the "store" namespace makes you think it is a store, but it is not.

Dojo Charting with DataSeries

This is a good URL I found for working with dojo charts and using a DataSeries.

Tuesday, September 20, 2011

Dojo charting axis bug

That didn't take long.  I found a bug with dojo where the titleOrientation: "away" setting for an axis on a chart is not honored.

Luckily someone reported the bug already.

Javascript Book

Can anyone recommend a good book about javascript that has topics such as MVC, OOP, closures, overall best practices, unit testing, etc.  Put the book title in the comments.

Dojo chart failed to render

I've been doing a lot of dojo lately.  I ran into an issue recently where I was creating a chart programatically and using a div tag as my target node.  The chart was not working.  The issue was because I had assigned a class to my div tag and the CSS behind the class was causing the chart to not show up.  I think dojo really wants to assign its own styling.  Here's the div that caused the problem:

<!--This is bad to use with dojo charting.-->
<div id="badChart" class="div-area"></div>

The solution is to nest this div tag inside another one.  Apply styling to the outer div tag to your heart's content.


Hi.  Welcome to my blog.  This blog is for random thoughts about software development.  If I run into a problem and figure out a fix... I'll post it!  Hopefully it will help others solve similar problems.  I'll also post about software development patterns and some of my own ideas.

The name.  I named this blog, "Less is More" because of a lot of software development principles that point to reduction;  DRY: Don't repeat yourself;  Don't make duplicate code;  Separate your concerns, don't reinvent the wheel; etc.  It is my belief that less code is more maintainable... by definition.  If you have less code, you have less to maintain.  Code maintenance accounts for the lion's share of work in the life cycle of most software applications.  A good developer should use all methods at their disposal to write minimal, maintainable code.  I'll write more on this later.  Have a great day!