Is it possible to access node/flow/global context properties from a ui-template node?
As it is now I have to wait for the first message to show anything. It could be useful to either access the data on the server side, and send it to the client along with other initial state. Or to pull the data from the server, during loading/initializing.
(I am setting up a Chart.js graph).
Hoping for some good ideas on that ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=12)
Is it possible to access node/flow/global context properties from a ui-template node?
Hi @dth - thanks for the question.
We don't pass the whole global
or flow
context store to the client, only msg
. So you'll need a "change" node ahead of where you want to access, then set something on msg.
to expose the relevant property/value pairing.
Thanks ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=12)
So no ways to load a widget with data from the initial page load (immediately after loading external javascripts, etc. is done)? A change node would have to be messaged after the javascript in the template node is ready.
Could perhaps be an idea to access context values on the server side for embedding data as a javascript array, or whatever, so the widget can have some state, before the first message arrives?
It seems that at least some of the other nodes essentially do this. Like for example a graph showing data, before receiving any messages.
We have a widget-load
event which is applicable here, but isn't exposed via an API to call.
Your best bet, if you want to ensure it's populated each time the widget is loaded is to use a ui-event
, that will fire on page load, pass data to the ui-template
node, which can store the msg
, then once the library is ready, use this.msg
accordingly.
If the chart
loads first, the other option you have is to put a watch
on msg
, and then act when payload
is set, checking if the library has loaded or not.
Some docs which may be useful:
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.