Store something after synchronization with auto-synchronization enabled

I am trying to detect and delete those fields that after synchronization are still stored in the repository but are not added to the database (success: false). Then return the error message to the user (with some error codes). However, I can only see the beforesync event in the store documentation.

Is there any way to do this? I try with the "update" events, but they are called after synchronization only if the synchronization is successful (otherwise they are called only before synchronization).

I can not find the event that fires after synchronization. Any solution for this?

Please note that I am using autoSync, so I cannot connect to the callback, otherwise everything will be easier.

Another important point that I see in the documentation:

the code:

Ext.data.Model.EDIT Ext.data.Model.REJECT Ext.data.Model.COMMIT 

Why does the REJECT event never fire? I thought that if success = false REJECT is called up, do I need something like 404 to get this result?

EDIT: No, I cannot find a way to trigger the REJECT version of the update event. Any suggestion?

+4
source share
3 answers

This, if you ask me, is some kind of design flaw in ExtJS.

AbstractStore has onCreateRecords , onUpdateRecords and onDestroyRecords , which are empty functions that you can override. You can call rejectChanges () if it has false.

 Ext.define('BS.store.Users', { extend: 'Ext.data.Store', model: 'BS.model.User', autoSync: true, autoLoad: true, proxy: { type: 'direct', api: { create: Users.Create, read: Users.Get, update: Users.Update, destroy: Users.Delete, }, reader: { type: 'json', root: 'data', }, }, onCreateRecords: function(records, operation, success) { console.log(records); }, onUpdateRecords: function(records, operation, success) { console.log(records); }, onDestroyRecords: function(records, operation, success) { console.log(records); }, }); 
+13
source

FYI: Event Sequence During Record Update (ExtJs 5.0.1)

 Scenerio 1 javascript executes record.set('some data') // Store has autoSync: true, The database will succeed 'update' event fires (operation = 'edit') 'beforesync' event fires network traffic occurs database returns a success (json) 'update' event fires (operation = 'commit') 'onUpdateRecord' method runs Scenerio 2 javascript executes record.set('some data') // Store has autoSync: true, The database will fail 'update' event fires (operation = 'edit') 'beforesync' event fires network traffic occurs database returns a failure (json) 'onUpdateRecord' method runs and calls rejectChanges() 'update' event fires (operation = 'reject') 'exception' event fires 

Two notes: a) the last update and onUpdateRecord are canceled, and b) if onUpdateRecord does not call rejectChanges (), the next update event does not fire. This will leave the record in a dirty state, which means that subsequent synchronization () will send it.

For record.add () the events are similar, but I see that the add event is not triggered. The Ext documentation for the event says that it is running, but the same documentation does not say that the add () method will fire the event.

+4
source

Another way around this is to use the suspendAutoSync and resumeAutoSync for the repository, and then manually sync (Ext JS> 4.1.0):

 store.suspendAutoSync(); store.insert(0, record); store.sync({ success: function (batch, options) { // do something }, failure: function (batch, options){ // handle error } }); store.resumeAutoSync(); 
+2
source

All Articles