Helping Sprouts Grow




Ask me anything

Debugging Tips! Part 1

I have had a heck of a time getting up to speed with regards to debugging my sproutcore app.  Hopefully you are already aware of Firebug & Safari Web Inspector . Sometimes I’m not able to step through in the debugger, for various reasons.  

(Quick hint! You can’t leave “debugger;” statements in and do an sc-build! It will fail.

Now, once you are in the console there are a couple useful tools accessible to you.  I know its incredibly unhelpful when you say 

var data = MyApp.store.find(MyApp.MyRecord)

[ > Object ]

Oh man, when I see [ Object ] I want to scream/cry, I’m used to cocoa description methods, which tell me so much more about the object.  I know its an object, be more helpful! ;)

  1. Try data.toString() to see what it looks like as a string
  2. Check the length, data.get(‘length’), this can be helpful in letting you know if any data is even present.
  3. Alternatively there is data.toArray() to see the object as an array
  4. data.readAttribute(‘someProperty’)

Use JSLint!  This tool has saved me so many headaches just on save & test alone. 

This last one, I’m embarrassed to admit, has caused me two serious headaches for far longer than they should have, and the fixes (partially) were so. simple! I cringe thinking about these.

Remember! Your! Case! If you are like me and used to camelCase, make sure you have not done DoubleCase in one place, and camelCase in another.

The final one is make sure you fully read your references.  I stared at code for hours before someone (Charles) pointed out that MyAppB.myController.arrangedObjects and MyAppE.myController.arrangedObjects were not the same thing.  I was glancing at the bindings, thinking yeah I’m binding to the controller arrangedObjects thats fine, what else could be wrong…  JS/Sproutcore won’t care that you are binding to MyAppB when you are in MyAppE and MyAppB doesn’t even exist. It can and will let you do this.

Big thanks to #sproutcore (Alex, Colin, Peter, Devin, etgryphon) and Charles Jolley for their help in debugging my numerous (and sometimes very simple) issues.  Thanks for your patience gentlemen.