I am making a messaging system that will allow operators to communicate between stations. I have a dataset tag for each station that stores all incoming and outgoing messages to all other stations. Not a large dataset as I don't think this feature will be used that often.
Because the dataset stores all of the messages to all other stations I have to filter it by station in the script transform and finally convert it to some html text to display. So I have a dropdown to pick what station you are messaging. Very similar concept to texts on your phone pretty much.
Problem is that switching the dropdown does not refresh the display because the tag binding is to the dataset. The dropdown value is grabbed during the script transform.
So I need a way to refresh the whole binding when the dropdown is used.
I would reverse the tag binding and dropdown functions. In other words, create a property binding to the dropdown value, then in your script transform, read your dataset tag there.
A binding is only refresh when a value changed in top of it (before the transform).
Can you delete all the transform, for each value change on the expression the binding will be refreshed, and it will be faster.
If not, you can call every tag in the base expression, to refresh on any change, and then use a transform to retreive all value you need and do what you want. It's slower for each transform you add.
Or you can call the now() function in the base expression to refresh every x time the binding
I thought of that but the problem is that I'll just have the reverse problem. No update on the display when a thread updates. Instead of now, no update when I change threads.
If I understand you right, You are saying I should change the binding type to an expression with both variables somewhere in the expression and then transform using the script?
Maybe but, how would I 'express' a property value of a component AND a dataset together to pass along to the transform without error?
and then in the individual expression, use the tagexpression function to get the tags value. I'm not sure if this is a good or a bad practice, but the expression exists!
I'd create 2 custom properties, put a tag binding on them, and then reference those properties in the structure binding.
It will be more efficient, and having the custom properties makes debugging easier.
If you are trying to use dynamic tag paths (e.g the 'tag' expression) an indirect tag binding is much more efficient.
Separating logic out into custom properties helps to keep your expressions short and readable, and also gives you access to intermediate data, particularly for troubleshooting when you haven’t got your logic quite worked out yet.
I generally avoid any use of the 'tag' expression. It is okay in some uses such as expression tags. In perspective it’s probably okay too, but the problem is if you get comfortable using it, you will lean on it when you shouldn’t and then you’ll be staring at performance issues.
So generally, if you think you need 'tag' take a step back and look for a better way.
I have a markdown box whose value is determined by the value of a dropdown component and also a dataset tag.
when you say create 2 custom properties, on what component? and then put a tag binding on both those properties, but to what two tags. There is only one tag value involved. Also, I suppose I'm posing the question back to you, what did you mean by 'it will be more efficient'? More efficient than what?
I guess I could see that. I suppose I don't prefer it though because it feels like 'extra steps'. It may be nice to troubleshoot now while I am developing this feature but 5 features from now when I have forgotten how I did it, I'd think it would just add to my confusion.
In this case I am not using an expression. But an 'expression structure' which returns an object made of 1 tag value and 1 dropdown value. Than I do all the fancy markdown logic and message filtering with a script transform. @YF129701 suggestion seems pretty straightforward and a good use of that feature.
I do understand the custom property argument. I have used it on other cases when I need to store a value but don't think a tag is appropriate. Usually a component specific value. But I don't think I want to add more bindings than are absolutely necessary by tag or property. That seems counterintuitive.
Yes, there is a reason it's called an Expression structure.
How are you getting the tag value? If the tag path is static, then okay, you can resolve that directly inside the structure. If it isn't, then I would strongly suggest that you use a property with an indirect tag binding (with potentially other properties for parts of the tag path), over using the tag() expression.
Also, I'm not sure what exactly you're doing in your script transform, but if you are concerned with performance, then an expression transform will be more performant than a script transform.
In this case it is static. Every station has their own dataset tag that holds messages that concern their station outgoing and ingoing. You might argue this doubles up data but like I said I don't expect these datasets to get very large and I might purge data that is over a month old anyways just to make sure its lightweight. But I see what you mean now.
Because the dataset of all outgoing/incoming messages needs to be filtered station, and also then converted to markdown to display the messages in a chat box. So I need python to do all of that.
If this is a pop-up are you creating a pop-up for every station? That seems like a lot of work (depending on how many stations there are I guess). Instead you could create a single pop-up with an indirect tag binding where the station number is a parameter to the pop-up.
Just an idea.
You might be surprised. I don't see anything there that would require scripting.
Every station has their own project/tag provider with identical tag structures. So in this case I am developing for one station and will scale up by copy pasting the project and changing the default tag provider (which also happens to be the station id) so I rarely have to use dynamic tags on anything. It's kind of built in. This page is an exception as it will allow any one station to view/chat any other station so in this case I am using dynamic tags but it's a dedicated page in each project. This isn't really a popup but there will be a notification bell built into every page. but now that you mention it...maybe I should make it a popup.
I don't know how else I would do this without python do dynamically create the markup every time there is a new message. What would you use?
I somehow thought two different tags were involved.
If the tag path is not built dynamically, then sure, just use {tag_path} in your expression.
But if you ever need to read a tag from a dynamically built path, I suggest you do a quick search on this forum, I'm sure you'll find enough reading material to convince you to go through custom properties.