PDA

View Full Version : What is (or should be) the relation between store.sync() and store.commitChanges()?



SergiuB
25 Feb 2013, 4:51 AM
If I update a Model instance in a Store, then do a sync, the respective Model's modified and dirty fields are not cleared after the sync is complete.
Should I do manually commitChanges after the sync is complete?

The reason I am asking is that I think I've uncovered a bug If I don't do commitChanges after sync.

I've reproduced it with the following test (I am using an Ajax mock to fake server responses):



singleResourceStore.load();
mostRecentAjaxRequest().response({
status: 200,
responseText: '[{"magicNumber":"1"}]'
});

singleResourceStore.first().set('magicNumber', "9999");
expect(singleResourceStore.getUpdatedRecords().length > 0).toBe(true);
singleResourceStore.sync();
mostRecentAjaxRequest().response(TestResponses.sync.success); // fake successful sync


singleResourceStore.first().set('magicNumber', "1");
expect(singleResourceStore.getUpdatedRecords().length > 0).toBe(true); // fails



I think the fact that modified and dirty flags are not cleared after sync() causes this issue.
If I call commitChanges after sync, the above code works.

SergiuB
25 Feb 2013, 7:21 AM
Please disregard the problem described in the previous post. It turned out there was a problem in a patch of ours in for the Json reader, which was causing the sync() method to fail.
I suppose this is the reason why the dirty flag was not cleared for the updated records.