0
votes

After comparing the documentation of the two classes, I am curious as to why one would use Ext.data.JsonStore as opposed to its superclass: Ext.data.Store. The documentation states the following about JsonStore:

Small helper class to make creating Ext.data.Stores from JSON data easier. A JsonStore will be automatically configured with a Ext.data.reader.Json.

The documentation then shows the typical configuration of a JsonStore as the following:

var store = new Ext.data.JsonStore({
    // store configs
    autoDestroy: true,
    storeId: 'myStore',

    proxy: {
        type: 'ajax',
        url: 'get-images.php',
        reader: {
            type: 'json',
            root: 'images',
            idProperty: 'name'
        }
    },

    //alternatively, a Ext.data.Model name can be given (see Ext.data.Store for an example)
    fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
});

The above code explicitly sets the reader type to 'json' - wouldn't the json type be implied in a JsonStore? This configuration doesnt seem any different to me than the way someone would configure a proxy to read a JSON file in an instance of Ext.data.Store.

Am I misunderstanding the use of Ext.data.JsonStore? If not, what is the benefit of using it over Ext.data.Store?

Thanks!

1
Ext.data.JsonStore is just a store preconfigured with an Ext.data.JsonReader, so actually a Ext.data.JsonStore is just a convenience class to make it easier for the developer. Check this answer.Sergey Novikov
I do it for one reason only: Readability. Everyone can deduce what a JsonStore does.Alexander

1 Answers

1
votes

Have a look at the definition of Ext.data.JsonStore:

Ext.define('Ext.data.JsonStore',  {
    extend: 'Ext.data.Store',
    alias: 'store.json',
    requires: [
        'Ext.data.proxy.Ajax',
        'Ext.data.reader.Json',
        'Ext.data.writer.Json'
    ],

    constructor: function(config) {
        config = Ext.apply({
            proxy: {
                type  : 'ajax',
                reader: 'json',
                writer: 'json'
            }
        }, config);
        this.callParent([config]);
    }
});