emm
3 Sep 2010, 3:06 AM
Sencha Touch version tested:
0.9 rev 3
only default ext-all.css
Description:
When removing an item in the store, WebStorageProxy destroys the first item instead of destroying the matching removed item.
Test Case:
In this sample code, second message should be destroyed in the localstorage, but it is first message that is removed.
Ext.regModel('Message', {
fields: [{name:'idid',type:'string'},
{name:'message', type:'string'},]
});
messageStore = new Ext.data.Store({
model: 'Message',
autoLoad: true,
autoSave: true,
batchUpdateMode: 'complete',
proxy: {
type: 'localstorage',
id : 'message',
/*
destroy: function(operation, callback, scope) {
var records = operation.records,
length = records.length,
ids = this.getIds(),
newIds = [].concat(ids),
i;
for (i = 0; i < length; i++) {
for (j = 0; j < ids.length; j++){
if (records[i].get('idid') == this.getRecord(ids[j]).get('idid'))
break;
}
newIds.remove(ids[j]);
this.removeRecord(ids[j], false);
}
this.setIds(newIds);
if (typeof callback == 'function') {
callback.call(scope || this, operation);
}
},
*/
}
});
Ext.setup({
icon: 'icon.png',
glossOnIcon: false,
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
onReady: function() {
message1 = {idid: '1', message: 'This is message 1'};
message2 = {idid: '2', message: 'Antoher message...'};
message3 = {idid: '3', message: 'A new message'};
messageStore.add(message1, message2, message3);
messageStore.sync();
messageStore.remove(messageStore.getAt(1));
messageStore.sync();
}
});
Steps to reproduce the problem:
run
The result that was expected:
second message removed
The result that occurs instead:
first message removed
Debugging already done:
checking the destroy method of WebStorageProxy, it doesn't seem to check what ids to remove
destroy: function(operation, callback, scope) {
var records = operation.records,
length = records.length,
ids = this.getIds(),
newIds = [].concat(ids),
i;
for (i = 0; i < length; i++) {
newIds.remove(ids[i]);
this.removeRecord(ids[i], false);
}
this.setIds(newIds);
if (typeof callback == 'function') {
callback.call(scope || this, operation);
}
},
Possible fix:
For my application, I've overriden the destroy method, and used my record's field 'idid' to check what id to remove.
Check the commented destroy method in code
0.9 rev 3
only default ext-all.css
Description:
When removing an item in the store, WebStorageProxy destroys the first item instead of destroying the matching removed item.
Test Case:
In this sample code, second message should be destroyed in the localstorage, but it is first message that is removed.
Ext.regModel('Message', {
fields: [{name:'idid',type:'string'},
{name:'message', type:'string'},]
});
messageStore = new Ext.data.Store({
model: 'Message',
autoLoad: true,
autoSave: true,
batchUpdateMode: 'complete',
proxy: {
type: 'localstorage',
id : 'message',
/*
destroy: function(operation, callback, scope) {
var records = operation.records,
length = records.length,
ids = this.getIds(),
newIds = [].concat(ids),
i;
for (i = 0; i < length; i++) {
for (j = 0; j < ids.length; j++){
if (records[i].get('idid') == this.getRecord(ids[j]).get('idid'))
break;
}
newIds.remove(ids[j]);
this.removeRecord(ids[j], false);
}
this.setIds(newIds);
if (typeof callback == 'function') {
callback.call(scope || this, operation);
}
},
*/
}
});
Ext.setup({
icon: 'icon.png',
glossOnIcon: false,
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
onReady: function() {
message1 = {idid: '1', message: 'This is message 1'};
message2 = {idid: '2', message: 'Antoher message...'};
message3 = {idid: '3', message: 'A new message'};
messageStore.add(message1, message2, message3);
messageStore.sync();
messageStore.remove(messageStore.getAt(1));
messageStore.sync();
}
});
Steps to reproduce the problem:
run
The result that was expected:
second message removed
The result that occurs instead:
first message removed
Debugging already done:
checking the destroy method of WebStorageProxy, it doesn't seem to check what ids to remove
destroy: function(operation, callback, scope) {
var records = operation.records,
length = records.length,
ids = this.getIds(),
newIds = [].concat(ids),
i;
for (i = 0; i < length; i++) {
newIds.remove(ids[i]);
this.removeRecord(ids[i], false);
}
this.setIds(newIds);
if (typeof callback == 'function') {
callback.call(scope || this, operation);
}
},
Possible fix:
For my application, I've overriden the destroy method, and used my record's field 'idid' to check what id to remove.
Check the commented destroy method in code