PDA

View Full Version : [STALE-383] Store in 0.96 not working properly



axxerion
1 Oct 2010, 11:55 AM
Very simple..

Create a store..



var store = new Ext.data.Store({
model: 'MyModel',
proxy: {
type: 'localstorage',
id : id
},
autoLoad: true
});


Add an item and sync



store.add({
id: theId,
field1: token,
field2:token2
});

store.sync();


If you go to the Google chrome storage... the record is added, but the index is wrong..
the index has: NaN as the first element... there seem to be something wrong with detecting what is new and what is an update..

BrendanC
1 Oct 2010, 4:08 PM
Thanks for the bug report.

axxerion
1 Oct 2010, 8:52 PM
I also did notice that when the idProperty of my Model is not an numeric value... the store.getById(value) is throwing an exception...

axxerion
1 Oct 2010, 9:48 PM
The problem seems to be located on the WebStorageProxy, in the method getIds... where the ids are being parsed to int...


ids[i] = parseInt(ids[i], 10);

axxerion
2 Oct 2010, 1:45 AM
Ok guys,.... even letting sencha generating its own id's the whole Store thing is not working properly... i keep getting all this NaN in the index... very randomly...

roady001
13 Oct 2010, 5:55 AM
I also have serious problems with Ext.data.LocalStorageProxy.


var FavoritesProxy = new Ext.data.LocalStorageProxy({
id : 'ListStoreFavoritesKey',
reader:{
idProperty: MyID'
},
});


1. There are trailing comma's (,) generated after adding records, which you can see with:

localStorage.getItem('ListStoreFavoritesKey')

After many frustrations to circumvent that one using a cleanup code, I get the next frustration:

2. Removing a record from the store:


ListStoreFavorites.removeAt(0);
ListStoreFavorites.sync();
doesn't really delete that first record (yes on the 'list' but not in the store itself). Refreshing the app just gets me many error's because NaN stuff is filling up


localStorage.getItem('ListStoreFavoritesKey') // Returns 1,2,4,5,6,NaN,NaN for example

edspencer
18 Oct 2010, 4:01 PM
Getting LocalStorage to work in a sensible way is rather tricky as everything is key/value strings and has to be encoded/decoded. It does currently make the assumption that your primary keys are numerical - I think that's a pretty normal and reasonable assumption but if there's a good reason why this doesn't make sense we can revisit it.

I'll investigate the trailing commas issue and get it resolved asap.

edspencer
18 Oct 2010, 10:00 PM
Ok I've just tried this with the following test case:



Ext.regModel('User', {
fields: [
'id', 'name', 'email'
],

proxy: {
type: 'localstorage',
id : 'user-test'
}
});

var store = new Ext.data.Store({
model: 'User'
});

store.add({
id: 1,
name: 'Ed',
email: 'ed@sencha.com'
});

store.add({
id: 2,
name: 'Fish',
email: 'fish@chips.com'
});

store.add({
id: 3,
name: 'Bonnie',
email: 'bonnie@clyde.com'
});

store.sync();


It works the same if you don't include the ids. I've attached a screenshot of my localStorage output at this point. If you can post code that produces a bug (this all seems correct) I'll be happy to fix it.

edspencer
21 Oct 2010, 12:33 PM
Bump. I will close this one down next week if it isn't updated as it doesn't seem like it is actually a bug.

joeri
25 Oct 2010, 10:33 AM
I'm having the same issue. parseInt is causing any non-number id not to work. I think this should be possible to get going.

edspencer
25 Oct 2010, 10:34 AM
I'd love to fix this but I can't do that without a reliable test case. If anyone who is getting this problem can post up exactly how to reproduce it I'll be happy to take a look.

BrendanC
4 Nov 2010, 5:22 PM
This thread appears to be stale.

joeri
5 Nov 2010, 12:07 AM
I will try to upload a test case this weekend.