Ext.direct is very nice in that it saves a lot of work - not so much making the AJAX calls themselves but in wiring up stores to AJAX calls and then attaching those stores to grids and tree controls and the like.

But writing my own server stack I've found myself being caught by a few gotchas that were maybe not so obvious from the docs, and thought I'd ask if anyone has found others they'd like to share

  • "update" calls should return all fields as if it were a "read". Originally I used "writeAllFields: true" in the JsonWriter attached to my DirectStore, but later changed this to false to make update messages shorter. This works fine but you must make sure that the server returns the full record for the object, not just the fields that were in the update, or the record in the datastore will have the missing properties removed. Obvious when you think about it, but caught me unawares when I first changed.
  • Plan to return your data as an object, not a list. The framework code will look for a 'success' member in the response result - if this is missing it's assumed to be be true, but if you ever want to return a valid 'success: false' then you'll have to have the result be an object, not a list or a single primitive value. Oh, and if you were thinking of having a record in the object that you return called 'success' be aware that ExtJS gives the field this special interpretation. This also applies to delete calls...
  • Plan what to do about phantom records and what to do when an proper ID is allocated. When records are added to the store they'll be marked as phantoms and given a local unique ID, but typically your back end will allocate a database identifier and return that, overwriting the phantom id, so don't go using the id of record as a key to something unless you know that you only record such items after you've received the response from them being written to the server
  • Sometimes you want to add extra fields to the call that creates a record on the server (eg I keep a store per user document, so the create call has to quote the document id) - do this by overriding the Writer's createRecord() method and add your extra fields here.

I'm sure there were more, but maybe I'll remember them later - trigger and thoughts of handy hints with anyone ??