If you’ve ever created a data store with the Sencha framework, you’re familiar with defining the “fields” for the store’s data.  Something like this does the trick:

var myStore = new Ext.data.JsonStore({
     id: "myJsonStore",
     url: "datasource.js",
     fields: [
          "id",
          "name",
          "age"
     ]
});

This method of defining data fields works perfectly well, but is not very extensible.  After all, what if you have several stores for which you want to use the same field definitions?  Yeah, you can define the same fields for each store, but wouldn’t it be better to define it once, and then customize it as needed?

Fortunately, this is super-simple to do.  When you define fields “inline” while creating the data store, what you are really creating is something of an impromptu MixedCollection (a Collection class that maintains both numeric indexes and keys and exposes events, per the docs).  Ah, so if it’s nothing more than a Sencha object, we can abstract it from the store itself, and reuse it to our heart’s desire!

var mydef = new Ext.util.MixedCollection();
mydef.addAll([
      "id",
      "name",
      "age"
]);

Obviously, this looks extremely similar to what we did inline.  However, the huge difference is that this new, abstracted object has some handy methods for retrieval, addition of index/keys, removal, and so on.  In other words, we can make a generic version of these field definitions, and then add to or take away from it as needed throughout an application. Nice!

Here’s the final product:

var mydef = new Ext.util.MixedCollection();
mydef.addAll([
      "id",
      "name",
      "age"
]);
var myStore = new Ext.data.JsonStore({
     id:     "myJsonStore",
     url:    "datasource.js",
     fields: mydef.getRange() 
});