Use of this.msg V this.$socket.on('msg-input:' + this.id, (msg)

I notice that people are using this.msg instead of

        mounted() {
            // listen for incoming msg's from Node-RED
            // note our topic is "msg-input" + the node's unique ID
            this.$socket.on('msg-input:' + this.id, (msg) => {


            }),

for tracking msg input

What are the advantages / disadvantages of each strategy?

Currently revealed difference is about reply message. The socet listening strategy helps to avoid it if needed. Overall the watch strategy offer cleaner and simpler codding. That's of course is opinion which doesn't qualify to be discussed.

I can't think of a reason for doing it, but does that mean one can listen for messages intended for other nodes, with a different id?

Yes. Just tried it

Sorry for being a bit slow, but would you explain this, I haven't seen anything about reply message apart from here and one of Colin's posts.

Yes, that is it: Retaining state information in a Dashboard 2 ui-template - #13 by hotNipi

Actually it is Replay Message.

Sorry typo.

But what IS replay message. I have haven't seen anything about this in the documentation. The only msg mentioned is this.msg which is the last msg received by the ui-template node

If you refresh the page (or open another browser window on it) then node red replays the last message sent to the template. That allows the node to set its current state, assuming that it only needs one message to do that (which is what the other thread is all about).

Well you learn something new every day!!

Yep, for clarification, as Colin has mentioned, this.msg can changed on 2 events:

  • widget-load: When the Dashboard/page first renders
  • msg-input: When an input arrives via Node-RED to the ui-template node

If you run a watch on msg, then that will fire in both of those instances. If you add your own socket listener, then it'll just fire when a new msg comes in via the input.

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