2016년 12월 29일 목요일

TinyDB valueIfTagNotThere misbehaving


This block reads a previously saved setting (font size) in TinyDB. In case it's the app's first run, the tag will not be there, but it needs to be created.
So I attached a DO block to the valueIfTagNotThere slot, which creates the tag and returns the default value (18).
Logically, the DO block should only be executed if the tag @font@size doesn't exist. But it actually returns 18 EVERY TIME even if the tag is already created and it has a different value in it.

In short: Is the DO block supposed to run even if the tag exists?

I attached a little sample of this condition, where you can type a value, touch a button to store it in TinyDB and touch another button to verify that the value was actually saved.
After quitting the app and opening it again, the value saved is lost and replaced by the DO block result, which I think it's the wrong behavior since the tag exist.
--
why do you want to save the default value? does this make sense?
why not just using this
-- 
Well, it's a little complicated to explain, but basically is because in other parts of the app I need to get that value again from the TinyDB, not from the components current values, which may have changed.
Anyway, the DO block shouldn't get executed if the tag exist, right?

-- 
app
just use the same block to get the default value in case the value is not there
KISS - keep it simple, stupid


Anyway, the DO block shouldn't get executed if the tag exist, right?

I don't know, but as already said, it does not make sense to use that block there

Taifun

-- 
I need the tags to exist because at some point in the app, I read all the tags and I need to create a listview with them but excluding the "settings" tags. So I can eliminate them to not show in the list. Anyway, I fixed that in another way.
The point here is not the method I'm using, The question remains the same. The DO block should not be executed if the tag exist.  (You may want to use the DO block there for other things, other than storing the tag).

-- 
I think the feature @Italo is expecting is called lazy evaluation.
And @Italo just proved that AI2 does not have that feature.

-- 
It looks like the same issue that occurs when a function is included as an item in a list.
When the list is created, even if the item is not selected the function is still evaluated.
So the process of evaluation in Italo's case results in the tag being created even though the tag exists.

-- 
Well, at least we now know how it works. Thanks guys.

-- 
See the post by FTurbak in the Open Source board this week under the BJ Search Facility thread, where he lists a couple of 
coming enhancements for this summer, including a  PHOLO paper, for more coding fun.

--
I could use that filtered list blocks in my app right now.
Thanks Abraham.

-- 


댓글 없음:

댓글 쓰기