Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no sync callback in Sencha Touch?

I'd like to be able to show a message to the user once a store sync has successful completion. However, there doesn't seem to be any way of using a callback or calling this synchronously. I'm a little surprised this isn't provided out of the box as it must be a common problem.

Is there any work-around for this?

like image 409
jaffa Avatar asked Oct 22 '22 21:10

jaffa


1 Answers

It took us ages to find a proper solution to this. Finally we added listener to the store's write event what seems to be working properly. As it is needed frequently it has been added to the store prototype as

Ext.data.Store.prototype.syncWithListener = function(onWriteComplete, syncMethod) {

    this.on('write', onWriteComplete, this, {single:true});

    var syncResult = syncMethod ? syncMethod.apply(this) : this.sync();

    if (syncResult.added.length === 0 &&
        syncResult.updated.length === 0 &&
        syncResult.removed.length === 0) {

        this.removeListener('write', onWriteComplete, this, {single:true});
        onWriteComplete(this);    
    }

    return syncResult;
};
like image 62
Zoltan Magyar Avatar answered Nov 10 '22 01:11

Zoltan Magyar