Login Register

custom data types

without knowing exactly what's going on behind the scenes, i would like to naively make a suggestion and get some feedback from those who have a better understanding of the dojo toolkit. please excuse me if what i'm suggesting already exists and i just haven't discovered it yet or if this is just a really bad idea - that would make this your chance to help me gain understanding.

my suggestion relates to custom data types in the stores. wouldn't it be more flexible to have a structure to define the type of each field in the store rather than require the server to declare the type and value? this would mean that the server can just simply encode objects into JSON and then the client can interpret the data as whatever it wants. it also seems that this gives you more control when you don't have control of the server's response.

you would declare your typeMap and then the structure i'm thinking of would assign a type to each field of the store based on the typeMap:

// adapted from http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/what-dojo-data/available-stores/dojo-data-item
var typeMap = {
     "Date": {
           type: Date,
           deserialize: function(value){
                return dojo.date.stamp.fromISOString(value);
            }
        },
    "String": {...
    },
    "Int": {...
    }
};

var storeFieldMap = {
    "date_added": "Date",
    "firstName": "String",
    "age": "Int"
};