Results 1 to 10 of 10

Thread: Proxy.js has Uses where it needs Requires

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Huntsville
    Posts
    252
    Vote Rating
    -4
      0  

    Default Proxy.js has Uses where it needs Requires

    Because of this line in the constructor:
    Code:
            if (this.model !== undefined && !(this.model instanceof Ext.data.Model)) {
                this.setModel(this.model);
            }
    Ext.data.Model should move from the uses to the requires array, like so:


    Code:
    Ext.define('Ext.data.proxy.Proxy', {
        alias: 'proxy.proxy',
        alternateClassName: ['Ext.data.DataProxy', 'Ext.data.Proxy'],
        requires: [
            'Ext.data.reader.Json',
            'Ext.data.writer.Json',
            'Ext.data.Model'
        ],
        uses: [
            'Ext.data.Batch', 
            'Ext.data.Operation', 
            //'Ext.data.Model'
        ],

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

    Default

    Can I get a test case where this is a problem?

    Ext.data.Store has Ext.data.Model in the requires so the Ext.data.Model will be required before the proxy is created.
    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 Premium Member
    Join Date
    Oct 2011
    Location
    Huntsville
    Posts
    252
    Vote Rating
    -4
      0  

    Default

    A Test case is not easily chopped out of my app. Static analysis should show you all you need to know. You can't uses Ext.data.Model in the constructor unless is is defined

    Which part of this don't you understand?

    Code:
    if (this.model !== undefined && !(this.model instanceof Ext.data.Model))
    
    The && means it will be evaluated if you are going to successfully create your Proxy, and you can't use instanceof on an undefined type.

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

    Default

    But where will a proxy be used without a Store or a Model? It could actually be removed from the uses and have zero effect except save a little framework size.
    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

  5. #5
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Huntsville
    Posts
    252
    Vote Rating
    -4
      0  

    Default

    It can't be used without the Model which is why the requires is necessary. You pass the Model NAME (as a string) into the Proxy and you error on the isinstanceof 'Ext.data.Model' because Ext.data.Model does not exist because it wasn't required.

    Part of this probably plays out because of this issue

    http://www.sencha.com/forum/showthre....js-works.-Why

    Which references another bug.

  6. #6
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,932
    Vote Rating
    548
      1  

    Default

    Quote Originally Posted by mitchellsimoens View Post
    It could actually be removed from the uses and have zero effect except save a little framework size.
    This would be a mistake as the code base would become harder to understand. Looking at Ext.define, I'd like to know class dependencies even if they are guaranteed to be already loaded.

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

    Default

    Code:
    Ext.define('MyModel', {
        extend : 'Ext.data.Model',
    
        fields : [...],
    
        proxy : {
            type : 'ajax',
            ....
        }
    });
    Code:
    Ext.define('MyStore', {
        extend : 'Ext.data.Store',
    
        model : 'SomeModel',
    
        proxy : {
            type : 'ajax',
            ....
        }
    });
    There really is no reason to ever Ext.create('Ext.data.proxy.Ajax', {...})

    And I said we *could* remove it and it would have no affect, not saying we are going to.
    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

  8. #8
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Huntsville
    Posts
    252
    Vote Rating
    -4
      0  

    Default

    Here is what I'm doing:

    Code:
    Ext.define('IHawk.viewer.data.BatchProxy', {
        extend: 'Ext.data.proxy.Ajax',
        model: 'Batch',
    ...

  9. #9
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,932
    Vote Rating
    548
      0  

    Default

    What's the problem to move the dependency from uses to requires? This would make the code more readable even if it doesn't fix anything.

  10. #10
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Vote Rating
    391
      0  

    Default

    In my opinion the requires for a class needs to be correct. Currently it is only used for dynamic loading but who knows what other uses the requires property will have in future, for example in build utilities.

    Given the current code I would say that Ext.data.Model needs to be in the requires for a proxy. The argument that proxies are only ever used with stores/models doesn't work for me.

    One use case (off the top of my head) would be a singleton proxy instance that is shared between many stores. This may be defined before the store/model is loaded and currently I think that would fail.

    I would actually suggest that a better solution to this is to remove the instanceof check and use isModel instead. Something like this maybe:

    Code:
    if (this.model && !this.model.isModel)) {
    There's probably a good reason why the original code explicitly checked for undefined rather than truthyness, but you get the idea.

    This removes the dependency on Ext.data.Model. However, there's still a dependency on Ext.ModelManager that I think should be explicitly included in the requires.

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
  •