Strange script bug
Strange script bug
c is the container, i is an item
It should remove the item, but it does not.
However it works without modifying anything even if you commit.
(It is extracted from a bigger script, perhaps the save is not necessary)
LL.save();
c.getProperties().edit().setEventHandler(“i.tap”,EventHandler.UNSET,null).commit();//doesn’t work
//c.getProperties().edit().commit();//does work
c.removeItem(i);
LL.save();
]]>« TrianguloY your calendar icon script is not working on my app drawer (Previous Post)
(Next Post) guys , i made a side bar and put inside it 17 apps icons »
< ![CDATA[
I think this could be because i is assigned before commit. Commit will trigger a reload of the container so that changes are taken into account. As a consequence the reference on the item i is not valid anymore. This would explain that edit().commit() works, because there is no change hence no reload. Re-getting the item by its id after the commit should work.
The fact that the container is reloaded is not documented. And even though it would be properly documented, I admit that the fact that references may become invalid isn’t obvious.
Maybe it could be possible to introduce an internal weak reference which would be dynamically resolved when the item is accessed, I’ll have a look at this.
]]>
< ![CDATA[
Oh, never thought of that.
Yes, taking the item again works.
Now I know it I won’t need that reference fix, but I see it will be useful in other cases, even for scripts that animate an item.
I also discovered another ‘bug’, if you remove the LL.save() before commit, changes made from script are not saved, or at least strange things happens. (Didn’t took the time to test all changes, but I guess that the sample without the LL.save() triggers it)
]]>
< ![CDATA[
LL.save() may save some item that would be reloaded because of a container change.
This is a caveat (that could probably be fixed by saving the container when needed before to run the commit…).
]]>