Sproutcore data source Tips.

Here are some tips I have found for building Sproutcore applications.

Just because you can make your data source REST doesn’t mean it’s a good idea. I usually send more than just basic information to my data sources. So I usually make the data source accept only post requests and simply send the information in the payload. Since get and some other verbs do not accept payloads, I find that it’s easiest just to make post request so that I can rely on consistant information accessed in in a consistant way.

The documentation states that remote queries are rare. Don’t feel that you should avoid them. While it is true that you can make “toMany” attributes on a model, and they are very useful, it is sometimes more beneficial to make a computed property that performs a remote query. This is particularly true if the attribute will not be used 100% of the time.

When deciding which attributes belong in a model and what types (toMany/remote query) they should be, keep in mind that you may want to reuse your models and in administration application. It is a good idea to create a framework that can be shared between your main application and your administration application. This framework would contain your data models, the base data source, and any custom views. Since my applications are strongly tied to a login, I put a base login controller in the shared framework as well.

My typical pattern when making a remote query is to simply return a list of IDs. The objects will be requested from the data source if they are not already available. While the retrieveRecords method of a store/dataSource is supposed to allow you to request multiple records at one time, it is usually only called with one ID at a time. I create a hash containing a store/model pairs that contain a list of IDs to request. When a request is made for a record, I add that ID to the hash and set a timer for a very short time (10 ms). The timer is reset if another record is requested. When the timer elapses, the actual request is made to the data source for all the records at one time. This cuts down on the amount of roundtrips to the server. And while it is true that a request for a single record will be slower, in the average case, where you are requesting more than one record, it should be faster.

Keep your database normalized, but feel free to de-normalize your models. Suppose for instance that you have a code table, that contains an ID at text name and possibly other data. If you normalize your model, you will begin to find timing errors in your application. The name will not show up in lists when you think it should. And you’ll wind up chasing your tail trying to get everything to load correctly when it is far simpler to simply create redundant name attributes in the models that would use your code table and supply them from the data source using a join.

Thursday, October 7, 2010

SproutCore Pre-report

I’ve been evaluating SproutCore and have moved forward using it for my project. The short version of the write-up is that is it much like Cappuccino without most of the problems I saw with Cappuccino (see the Cappuccino writeup). I still plan to have a full writeup of SproutCore and publish the framework I’m writing.

Also looking into Selenium for automated testing.

Wednesday, July 21, 2010

AT-AT Day Afternoon

Badass JavaScript: PDF.js - Create PDFs in JavaScript

Marak Squires has released PDF.js, which lets you create PDFs in JavaScript, either in the browser or on the server with Node.js. It has a simple API that you can use to add pages and text (image support is coming soon) to your PDF documents. In the browser, PDFs are exported through…

Reblogged for future use ;)

Reeder for iPad

I’m 5 days late with this. I’d given up hoping for it, but my favorite news reader has come to the iPad.

Creepy Watson

BP Spills Coffee — Gotta love Upright Citizens Brigade

Whatever: The Blog of John Scalzi. One of my favorite authors.

Gentleman, I give you … House cat. That’s my cat Scooby after she climbed up the ladder.

Gentleman, I give you … House cat. That’s my cat Scooby after she climbed up the ladder.

In “honor” of my mother receiving a 419-style inquiry from her listing on CareerBuilder, I give you Monty Python’s “Dead Parrot Sketch” performed by (tricked) Nigerian email scammers.

Also, here is CareerBuilder’s Scam Page