save override & create new one
Closed this issue · 4 comments
Hi all, thank you for this great script! :D
I'm having an issue when I try to save my object, my object dont have a key at the first time, it create one automatically, then I try to save (override) this object in lawnchair and the I get a new one, with the same key and the 2 objects are modified.
Example: notes.save({name: 'value', selected: false});
after: notes.save({key: 654654654, name: 'changed', selected: true});
and what I get is 2 notes with the key 654654654, name: changed and selected to true.
Hope I can get this issue resolved, thank you! :D
Also for my settings one, when I save always the same key : settings , I get this array :
["settings","settings","settings","settings","settings","settings","settings","settings","settings","settings","settings","settings","settings","settings"]
Thank you
I had same problem and just found out why:)
I'm using ver. 0.6.1.
There is a small bug in the source code.
Change the code on line 215 in lawnchair-0.6.1.js like below...
if (!this.indexer.find(key)) this.indexer.add(key) => if (false === this.indexer.find(key)) this.indexer.add(key)
Then it should work!
The function "this.indexer.find(key)" returns 0, if the key would be found at first place of the Array of index keys.
That was the problem.
Oh ok thank you, but I've created my own json storage similar to lawnchair so I dont use anymore Lawnchair, but thx for the help :D
Thanks for mentioning this. I was running into this as well with the version I downloaded... I fixed it as mentioned above.... The fix in the minified version is as follows:
save:function(a,c){var e=a.key||this.uuid();!(this.indexer.find(e)===false)||this.indexer.add(e);delete a.key;this.storage.setItem(e,JSON.stringify(a));if(c){a.key=e;this.lambda(c).call(this,a)}return this}