Results 1 to 3 of 3

Thread: This behavior seems contrary to the documentation, can someone please explain?

  1. #1
    Sencha User
    Join Date
    Jan 2013
    Posts
    19
    Vote Rating
    0
      0  

    Default This behavior seems contrary to the documentation, can someone please explain?

    The ModelManager documentation states "The following snippets are equivalent":

    Code:
    // method 1, access model type through the manager
    var UserType = Ext.ModelManager.getModel('User');
    // method 2, reference the type directly
    var UserType=User;
    This does not seem to be the case, however. Take this simple example:

    Code:
    Ext.define('Config', {
      singleton: true,
      extend: 'Ext.data.Model',
    
      config: {
        fields: [
          {name: 'id', type: 'int'},
          {name: 'email', type: 'string'},
          {name: 'password', type: 'string'},
          {name: 'username', type: 'string'},
        ],
        proxy: {
          type: 'localstorage',
          id: 'config',
        }
      }
    });
    
     var ConfigModel = Ext.ModelManager.getModel('Config');
    (Working example here: http://new.senchafiddle.com/#/KcBy6/)


    Given the code above, here's the odd part:


    Directly
    Config.save() exists.
    Config.load() doesn't exist.

    via ModelManager
    ConfigModel.save() doesn't exist.
    ConfigModel.load() does exist.

    What is going on here? Why don't I have consistent access to load() and save()? This not only seems very odd, but also appears to contradict the whole equivalency thing mentioned in the ModelManager documentation.

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    This code isn't really valid for what you usually want to have:

    Code:
    Ext.define('Config', {
      singleton: true,
      extend: 'Ext.data.Model',
    
      config: {
        fields: [
          {name: 'id', type: 'int'},
          {name: 'email', type: 'string'},
          {name: 'password', type: 'string'},
          {name: 'username', type: 'string'},
        ],
        proxy: {
          type: 'localstorage',
          id: 'config',
        }
      }
    });
    The singleton property will automatically create an instance so Config will be an instance not a definition.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Jan 2013
    Posts
    19
    Vote Rating
    0
      0  

    Default

    Are there any downsides to our Model being an instance v.s. a definition?

    Am I losing anything by not having a definition available?
    Can I recall the definition through an instance (e.g. Config.constructor)?
    What is the difference between a definition of an instance in Ext.js/Touch?


    As I saw/see it, my application will only ever have one single user. In this case, there is no need to use a Store (which looks from just about every documented example to be intended as a collection of instances).

    Am I correct in this understanding?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •