1. #1
    Sencha Premium Member
    Join Date
    Jun 2013
    Location
    Boulder, CO
    Posts
    541
    Vote Rating
    10
    DavidThi808 will become famous soon enough

      0  

    Default Why does Architect create a store constructor?

    Hi all;

    The latest samples I see say do not create a constructor. And define a store with declarations as follows:

    Code:
    Ext.define('AM.store.Users', {    extend: 'Ext.data.Store',
        model: 'AM.model.User',
        autoLoad: true,
    
    
        proxy: {
            type: 'rest',
            api: {
                read: '../Service1.svc/GetEmployees',
                update: '/Service1.svc/SaveEmployee'
            },
            reader: {
                type: 'json',
                root: 'users',
                successProperty: 'success'
            }     ,
            writer: {
                type: 'json'
            }
        }
    });
    But architect creates a constructor as follows (as I tried to do the same thing as the example, but in Architect):

    Code:
    Ext.define('MyApp.store.MyStore', {    extend: 'Ext.data.Store',
    
    
        requires: [
            'MyApp.model.MyModel'
        ],
    
    
        constructor: function(cfg) {
            var me = this;
            cfg = cfg || {};
            me.callParent([Ext.apply({
                autoLoad: true,
                model: 'MyApp.model.MyModel',
                storeId: 'MyStore',
                proxy: {
                    type: 'rest',
                    api: {
                        read: '../Service1.svc/GetEmployees',
                        update: '/Service1.svc/SaveEmployee'
                    },
                    reader: {
                        type: 'json',
                        root: 'users'
                    },
                    writer: {
                        type: 'json'
                    }
                }
            }, cfg)]);
        }
    });
    Why? Is Architect just doing things the old way? Or are the samples out of date?

    thanks - dave

  2. #2
    Sencha Premium Member
    Join Date
    Jun 2013
    Location
    Boulder, CO
    Posts
    541
    Vote Rating
    10
    DavidThi808 will become famous soon enough

      0  

    Default

    Asking again.

    thanks - dave

  3. #3
    Sencha User aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,487
    Vote Rating
    139
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default

    Complex objects that are stored on the prototype of an object will be shared by reference unless specifically addressed in the class (in this case Ext.data.Store). Store does handle dealing with this case.

    However, in general I think complex types should only be stored on the prototype if you are using the config system or plan to use that variable as a static type.

    I've linked a brief snippet that illustrates the problem with storing complex types on the prototype of a class.
    https://fiddle.sencha.com/#fiddle/b7
    Aaron Conran
    @aconran

  4. #4
    Sencha Premium Member
    Join Date
    Jun 2013
    Location
    Boulder, CO
    Posts
    541
    Vote Rating
    10
    DavidThi808 will become famous soon enough

      0  

    Default

    got it - thanks

Thread Participants: 1