PDA

View Full Version : [2.1.0] Record edits do not trigger 'beforesync' when a localstorage store is synced



stefankendall
12 Nov 2012, 4:19 PM
Adding a record and syncing triggers beforesync. Editing does not. Full example below. Expected: 2 alerts. Actual: 1 alert.



<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="js/sencha-touch-2.1.0/resources/css/sencha-touch.css"/>
<script type="text/javascript" src="js/sencha-touch-2.1.0/sencha-touch-all.js"></script>
<script type="text/javascript">
Ext.define('Lift', {
extend:'Ext.data.Model',
config:{
identifier:'uuid',
fields:[
{name:'id', type:'string'},
{name:'name', type:'string'}
],
proxy:{
type:'localstorage',
id:'lift-proxy'
}
}
});


var store = Ext.create("Ext.data.Store", {
model:'Lift'
});


store.add({name:'Hi!'});
store.sync();
store.addListener("beforesync", function () {
alert("Sync called!");
});


store.first().set('name','bye!');
store.first().save();
store.sync();


store.add({name:"WUT"});
store.sync();
</script>
</head>
<body>
</body>
</html>

mitchellsimoens
12 Nov 2012, 4:43 PM
You have this:


store.first().save();

which the store.sync(); right after that doesn't think it has anything to sync. When I remove that then I get the Sync Called logged twice as expected.

stefankendall
12 Nov 2012, 6:00 PM
My real scenario has a validation which appears to be stopping the beforesync callback. I'll track it down.

Regardless, firing 'sync' *always* used to fire the beforeSync event.