View Full Version : Accessing proxy operation externally?

11 Aug 2011, 6:30 PM
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:

// Creation of proxy
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
//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){

// 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){
dataChanged: function(store) {

And here's the faked call to the streaming source:

// 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? (http://stackoverflow.com/questions/7035009/sencha-touch-accessing-proxy-operation-externally)

12 Aug 2011, 7:33 AM
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
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):

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.

21 Aug 2011, 6:00 PM
Maybe mark your own post as answered?

21 Aug 2011, 6:01 PM
Oh dear, that feels almost wrong! But still good.