PDA

View Full Version : Local Storage - store.remove() doesn't sync Local Store



cassebn
3 Jan 2011, 10:41 AM
When using a local storage proxy and removing a record the actual record gets removed from the store but upon sync() doesn't truly get removed from local storage. When a user refreshes their screen the removed record still exist.

Any ideas as to if this is a bug with Sencha Touch 1.0.1 or if I just have an issue with my code listed below? If a bug, will it be fixed with release of 1.0.2? any help is greatly appreciated.



Ext.regModel('MusicModel', {
fields: [{
name: 'name',
type: 'string'
}, {
name: 'path',
type: 'string'
}]
});
Ext.regStore("FavoritesStore", {
model: 'MusicModel',
sorters: 'name',
getGroupString: function(record){
return record.get('name')[0];
},
proxy: {
type: 'localstorage',
id: 'favorites-store-proxy',
proxy: {
idProperty: 'name'
}
},
autoLoad: true
});
// This is the function that is then called that passes in a valid record to remove:
removeFromFavorites: function(record){
var favorites = Ext.StoreMgr.get('FavoritesStore');
var r = favorites.findRecord('name',record.data.name);
favorites.remove(r);
favorites.sync();
}

mitchellsimoens
15 Jan 2011, 2:32 PM
I'm going to bump this because I am getting the same problem. I have also found these other two threads that haven't been solved either:

http://www.sencha.com/forum/showthread.php?119745-LocalStorage-for-Application-Settings-and-remove&highlight=local+storage+remove
http://www.sencha.com/forum/showthread.php?113259-Objects-not-removed-from-localStore-(0.97)&highlight=local+storage+remove

tomalex0
17 Jan 2011, 10:15 PM
I'm working with version 1.01a. I have worked with localstorage it seems add and remove is working for me, some time i came across a problem but i couldn't able to recreate it

Below mention code works for me, let me know if any problem occurs


Ext.setup({
onReady: function() {

Ext.regModel('Contact', {
fields: ['email'],
proxy:{
type:'localstorage',
id :'contact'
}

});

var contactStore = new Ext.data.Store({
model:'Contact',
getGroupString : function(record) {
return record.get('email')[0];
},
autoLoad:true
});

var mainPanel = new Ext.Panel ({
fullscreen:true,
scroll:false,
dockedItems:[{
xtype:'toolbar',
items:[{text :'Disclosure to Remove'},{xtype:'spacer'},{
text:'Add to Local Storage',
handler:function(){
Ext.Msg.prompt("Welcome!", "Enter Email", function(stat,val){
if(stat == "ok"){
if(contactStore.findExact('email',val) == -1){
contactStore.add({email : val});
contactStore.sync();
}
}
});

}
}]
}],
items:[{
xtype:'list',
fullscreen: true,
itemTpl : '{email}',
onItemDisclosure: {
handler: function(record, btn, index) {
contactStore.remove(contactStore.findRecord('email',record.get('email')));
contactStore.sync();
}
},
grouped : true,
indexBar: false,
store: contactStore
}]
});
}
});

SpNg
15 Feb 2011, 10:25 AM
I am also having this problem. Adding works fine, but removing is not syncing...

chummy
20 Feb 2011, 11:22 PM
It works for me if I add a field called "id" of type "int" to the model. Sencha Touch will populate the field. It seems, from having a quick look at the code, that Sencha Touch uses this field to identify the instance of the record that it must delete from the store.

mitchellsimoens
21 Feb 2011, 5:01 AM
Ok, we can close this thread as it's working in the last couple versions now.

SpNg
21 Feb 2011, 9:13 AM
Yep this works for me now. The id field was the key. Thanks for the response!

mikermcneil
12 Apr 2011, 12:08 AM
Still happening to me in 1.1. I tried the "id" fix chummy suggested and it worked. (didn't bother making it of type int).

mitchellsimoens
12 Apr 2011, 5:40 AM
Still happening to me in 1.1. I tried the "id" fix chummy suggested and it worked. (didn't bother making it of type int).

So the fix worked in 1.1.0?

mikermcneil
13 Apr 2011, 7:31 AM
Yup. You'll probably find you need to clear your LocalStore.



// Set up local user state model template
User.template = Ext.regModel('User', {
fields: [
'id', // DONT TOUCH

// User identity
'user_id',
'secret',

// Personal info
'firstName',
'lastName',
'email',
'website',
'portrait_url',
'twitter_screen_name'
]
});

// Proxies
User.remoteProxy = new Ext.data.AjaxProxy({
model: 'User',
url: User.proxyURL,
reader: {
type: 'json'
},
type: 'ajax',
actionMethods: {
read: 'POST'
},
id: 'user_remote'
});
User.localProxy = new Ext.data.LocalStorageProxy({
model: 'User',
type: 'localstorage',
id: 'user_local'
});

mitchellsimoens
13 Apr 2011, 7:36 AM
remove is working for me on 1.1.0 and removes only that record in local storage.

You can do a search in the forum and you may see some overrides floating around I made to fix certain bugs in removing.

C.S.
3 May 2011, 5:01 PM
K I'm a little confused by this thread - but it is the first result in google and is EXACTLY the problem I am experiencing atm.

I have Sencha Touch 1.1.0 loaded in Chrome 10 (desktop - for some initial dev work) and as it was records were not getting removed from the Local Storage.

I am actually using this project (http://www.sencha.com/forum/showthread.php?118453-Mobile-Chat-with-Sencha-Touch-node.js-socket.io) that I have modified to run over normal web sockets.

I hadn't even touched the Ext.Store chunks of code, but now I'm having to add this 'id' field to the store structure - which does indeed magically fix the remove/sync abilities.

So is it "as designed" that an 'id' field must be present for the store to function properly or is there a problem in 1.1.0 that still needs to be fixed?

(Or is that demo project just designed bass-ackwards to begin with maybe?)

sonic555gr
2 Feb 2012, 7:59 AM
Hello!
It's been a year since the last response to this thread. I am having a different kind of problem with the localstorage. The removal of items from local storage works fine but after i remove the last item the local storage becomes unusable.

In chromes debugger i see the local storage populated with 1 key for the proxy lets say that the proxy's id is
'favoritesOffersProxy' after i add an item with id 57 i get 2 records. One that is the proxy and another that is the record. After i remove the record the proxy gets deleted also, so the local storage gets unusable and i have to refresh the page to initialize my proxy again... does anyone have any idea how to resolve this?

this is my store

app.stores.FavoritesOffersStore = new Ext.data.Store({
id:'favoritesOffersStore',
model:app.models.OffersModel,
autoLoad:true,
proxy:
{
id:'favoritesOffersProxy',
type: 'localstorage'
}});
and i delete a record like this


app.stores.FavoritesOffersStore.remove(item);
app.stores.FavoritesOffersStore.sync();

If you have any questions about what exactly i'm talking about, don't hesitate to contacte me!

Thank you!

sixin
17 Jan 2013, 8:21 AM
It works for me if I add a field called "id" of type "int" to the model. Sencha Touch will populate the field. It seems, from having a quick look at the code, that Sencha Touch uses this field to identify the instance of the record that it must delete from the store.
thanks this works for me :)