I have made a timer script to simulate tags that are similar to MQTT engine, such that it will update the timestamp in 10 sec now in view I have made a message with label that after 30 sec if timestamp is not updating then it will make visible the message "Data is stale not fresh", but when I am stoping the timer script the value inside the visiblity (edit binding) is changing but it is not coming to the component only if I press ok or apply it will get updated in the component visiblity.
This is my timer script:
on yellow marked is timestamp that I am making visiblity script.
Below is my visiblity on embeded component.
Also below is my timestamp difference calculation script that I am using in visiblity component:
There are a few things wrong here. The issue itself is that a tag binding, regardless if it has transforms on it, will only update when the root binding changes, in this case the tag. So if the tag stops updating, your binding won't fire.
The second issue is, script transforms should be the absolute last resort if you can't do something with an expression binding, which you can in this case with coalesce(secondsBetween(now(1000), {value}) >= 30, True)
(I would format that nicer but I can't on mobile...)
I have written this code in expression binding is it correct? if you can confirm.
Thanks.
You shouldn't use the tag() expression function anywhere but within expression tags due to performance issues.
You should also either use an indirect tag binding with an expression transform, or better, create a custom prop and bind your tag to that, then in another custom prop, use an expression binding with:
!isGood({view.custom.tagValue}) ||
secondsBetween({view.custom.tagValue}, now(1000)) >= 5
Notes:
-
the preference is to create custom props on the "view" itself rather than at parent component levels for most cases where you need refer to it from a nested child component to avoid breaking links if you move the child components around such as within other containers.
-
you should avoid if statements that return true or false and prefer boolean statements instead for readability