# Retaining state information in a Dashboard 2 ui-template

**URL:** <https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007>\
**Category:** Dashboard\
**Tags:** dashboard-2\
**Created:** [28 February 2024 16:39 UTC](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007 "2024-02-28T16:39:05Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [1 March 2024 15:28 UTC](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007/21 "2024-03-01T15:28:00Z")

</div>

I haven't worked (real paid work I mean) on solutions where state of something is/should be stored. (except user choice of something very trivial which goes to localstorage)  
Here the dashboard 1 & 2 both offer that. I have been living with that (fighting a lot when creating widgets) but for myself I still created dashboard with classical "request-response / register" solution. I do understand it and it is as reliable as the socket connection can be (and quality of my coding).

But there's not much choice here. It is just freakingly easy to rely on framework solutions, maybe bend them a bit. It is worth of it. It cuts down way more than half of codding needed. And that makes the difference. I don't blame, I love the result.

Maybe to dive in deep (a lot of investigations just to educate myself) may make my mind more clear about it but that takes time which i have just a bit if even that mostly 🙂

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 March 2024 15:48 UTC](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007/22 "2024-03-01T15:48:18Z")

</div>

> [@hotNipi](#):
>
> classical "request-response / register" solution

Can you explain what you mean by that please?

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [1 March 2024 15:57 UTC](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007/23 "2024-03-01T15:57:24Z")

</div>

All created elements (if they depend on data) are coded to be able to request and receive data from server via some central communication logic. It can be one time request or register to listen updates. There is defined communication protocol which is same for frontend and server so both sides codded to follow the protocol and act accordingly.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 March 2024 16:17 UTC](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007/24 "2024-03-01T16:17:33Z")

</div>

Understood.  
How would you do that in the context of a ui-template node? Is it possible to do it via the existing socket connection?

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [1 March 2024 16:31 UTC](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007/25 "2024-03-01T16:31:10Z")

</div>

Widget on mounted sends request. Server firues out by protocol what to do and sends payload.

As the template doesn't know anything about the protocol it is kind of manual thing per widget which is not pleasent thing to make or maintain.

This is not strategy which fit into the overall logic of build dashboard by configuring widgeds and fire. It takes custom coding on both sides and current communication which exists will be only obstacle in a way.  
I can't see win her at all .

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 March 2024 16:44 UTC](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007/26 "2024-03-01T16:44:02Z")

</div>

OK, thanks. It looks like I will have to resort to putting Join nodes on the front of my widgets, or Function nodes for more complex conditions.

---

<div class="post-metadata">

**Author:** ![joepavitt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joepavitt/32/59722_2.png) [@joepavitt](https://discourse.nodered.org/u/joepavitt)\
**Post date:** [1 March 2024 17:46 UTC](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007/27 "2024-03-01T17:46:47Z")

</div>

> [@Colin](#):
>
> If the node is disabled and then another user opens a browser window on the node it has to be in the disabled state.

Why not utilise Node-RED's `global.` or `flow.` state stores for this?

> [@Colin](#):
>
> The core ui nodes presumably use server side state for such information

You are correct, we have a `statestore` and `datastore` on the server-side of Dashboard 2.0 for this exact purpose. There are client-side equivalents, but their state is lost on refresh, and re-filled with whatever the known server-side state is on first load.

> [@Colin](#):
>
> As I understand it there is no server side storage associated with the template other than the configuration and the last message sent

Each `ui-template` does have a statestore/datastore, but I don't expose those to the client-side _currently_. My reasons for doing so is that it very quickly becomes easy to abuse and memory leaks could get very out of hand, very quickly as developers would use it like a database, which isn't a reliable/efficient thing to do.

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [1 March 2024 18:06 UTC](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007/28 "2024-03-01T18:06:33Z")

</div>

> [@joepavitt](#):
>
> very quickly as developers would use it like a database,

That concludes the topic. There's no reason to ruin your experience with dashboard even of you do it for yourself.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 March 2024 21:37 UTC](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007/29 "2024-03-02T21:37:59Z")

</div>

> [@joepavitt](#):
>
> > [@Colin](#):
> >
> > If the node is disabled and then another user opens a browser window on the node it has to be in the disabled state.
> 
> Why not utilise Node-RED's `global.` or `flow.` state stores for this?

Because they are not available in the client.

> [@joepavitt](#):
>
> Each `ui-template` does have a statestore/datastore, but I don't expose those to the client-side _currently_. My reasons for doing so is that it very quickly becomes easy to abuse and memory leaks could get very out of hand, very quickly as developers would use it like a database, which isn't a reliable/efficient thing to do.

I am not entirely convinced by that argument. Could you not make the same argument about server side storage and contributed ui nodes?  
The result is that responsible developers have to build more complex flows than they would otherwise.  
All I need is a boolean and two short strings.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 April 2024 21:38 UTC](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007/30 "2024-04-01T21:38:08Z")

</div>

Closed on 1 April 2024 21:38 UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/retaining-state-information-in-a-dashboard-2-ui-template/86007.md?page=1)
