-
11 Aug 2011 6:30 PM #1
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?
And here's the faked call to the streaming source: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'); } } });
Many thanks for reading and I would be grateful for any possible answers.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); }
I've also posted this on stackoverflow: Sencha Touch - accessing proxy operation externally?
-
Best Answer Posted by andymoreno
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):
And placed that in the callback function... done.Code:AT.stores.services.loading = false;
Sidenote: I don't really know if this thread is answered or what?
Thanks for your time.
-
12 Aug 2011 7:33 AM #2
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?
-
21 Aug 2011 5:43 PM #3
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):
And placed that in the callback function... done.Code:AT.stores.services.loading = false;
Sidenote: I don't really know if this thread is answered or what?
Thanks for your time.
-
21 Aug 2011 6:00 PM #4
Maybe mark your own post as answered?
Twitter: lylepratt
-
21 Aug 2011 6:01 PM #5
Oh dear, that feels almost wrong! But still good.
Thanks!


Reply With Quote