1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    4
    Answers
    1
    Vote Rating
    0
    andymoreno is on a distinguished road

      0  

    Default Answered: Accessing proxy operation externally?

    Answered: Accessing proxy operation externally?


    I'm creating a Sencha Touch app that gets it's data from a streaming JS source. My plan was to build my own proxy to CRUD the data into the store/model structure.


    The current code works, but the Loader spinner never goes away due to the proxy's read operation doesn't complete in the regular way, and it just feels like I'm going to run into problems later on...


    My questions;
    • am I approaching this from the right direction?
    • how would I set the operation.setSuccessful and operation.setCompleted from my callback function that is outside the proxy altogether?
    Here's my proxy/callback/model/store setup:


    Code:
    // Creation of proxy
    Ext.data.ProxyMgr.registerType("proxyServices",
        Ext.extend(Ext.data.Proxy, {
            create: function(operation, callback, scope) {
            },
            read: function(operation, callback, scope) {
                // My call to the streaming source,
                // this will completely break the 'normal' rhythm of the operation
                getServicesByResourceId(null, AT.callbackServices);
    
    
                // this is the part I want to reach
                operation.setSuccessful();
                operation.setCompleted();
                //finish with callback
                if (typeof callback == "function") {
                    callback.call(scope || thisProxy, operation);
                }
            },
            update: function(operation, callback, scope) {
            },
            destroy: function(operation, callback, scope) {
            }
        })
    );
    
    
    // The callback from the streaming source
    AT.callbackServices = function(data){
        Ext.each(data, function(item, index){
            AT.stores.services.add(item);
        });
    };
    
    
    // Model
    AT.models.Service = Ext.regModel('Service', {
        fields: [
            {name: "id"},
            {name: "description"}
        ],
        proxy: {
            type: "proxyServices"
        }
    });
    
    
    // Store
    AT.stores.services = new Ext.data.Store({
        model: "Service",
        autoLoad: true,
        listeners: {
            beforeload: function(store, opt){
                //console.log('beforeload');
            },
            dataChanged: function(store) {
                //console.log('dataChanged');
            }
        }
    });
    And here's the faked call to the streaming source:


    Code:
    // Fake call to streaming source
    var _services = [
        {id:1, description:'service1'},
        {id:2, description:'service2'},
        {id:3, description:'service3'}
    ];
    function getServicesByResourceId(resourceId, callback) {
        setTimeout(callback, 300, _services);
    }
    Many thanks for reading and I would be grateful for any possible answers.

    I've also posted this on stackoverflow: Sencha Touch - accessing proxy operation externally?

  2. Well, I've managed to get it to do what I want, in my homecooked proxy... I'm not convinced it couldn't be done better though.

    Got rid of the loading spinner with a pretty simple line of code (that took me several days to find):

    Code:
    AT.stores.services.loading = false;
    And placed that in the callback function... done.

    Sidenote: I don't really know if this thread is answered or what?

    Thanks for your time.

  3. #2
    Touch Premium Member lylepratt's Avatar
    Join Date
    Dec 2010
    Location
    Austin, Texas
    Posts
    159
    Answers
    3
    Vote Rating
    0
    lylepratt is on a distinguished road

      0  

    Default


    You might be better off not using a proxy at all. Just manually add items to the store.

    Do you need the other CUD operations?

  4. #3
    Sencha User
    Join Date
    Aug 2011
    Posts
    4
    Answers
    1
    Vote Rating
    0
    andymoreno is on a distinguished road

      0  

    Default


    Well, I've managed to get it to do what I want, in my homecooked proxy... I'm not convinced it couldn't be done better though.

    Got rid of the loading spinner with a pretty simple line of code (that took me several days to find):

    Code:
    AT.stores.services.loading = false;
    And placed that in the callback function... done.

    Sidenote: I don't really know if this thread is answered or what?

    Thanks for your time.

  5. #4
    Touch Premium Member lylepratt's Avatar
    Join Date
    Dec 2010
    Location
    Austin, Texas
    Posts
    159
    Answers
    3
    Vote Rating
    0
    lylepratt is on a distinguished road

      0  

    Default


    Maybe mark your own post as answered?
    Twitter: lylepratt

  6. #5
    Sencha User
    Join Date
    Aug 2011
    Posts
    4
    Answers
    1
    Vote Rating
    0
    andymoreno is on a distinguished road

      0  

    Default


    Oh dear, that feels almost wrong! But still good.

    Thanks!

Thread Participants: 1

Tags for this Thread