I am trying to build a third party widget. It consists of a v-btn-toggle, a slider an one other button (and some other elements).
When i toggle, i am able to emit a custom event, receive that event at the serverside.js and do some calculations. As a result of these calculations i would then like to update some props (color of some elements).
I am able to set the props via statestore.set but widget does not update/rerender.
When i manually rerender (reload browser) then props are updated.
Yes indeed that is the new way of working. You can find examples of how it has been implemented e.g. for the ui-text node here. More specifically have a look at the server side code:
SocketIO traffic is one-way, with the pub/sub model. So you'd need another custom event to transport the server-side back to the front-end outside of the standard onInput, onChange, onAction handlers.
I do expose a .emit(event, msg, node) on the UI Base elements, so assuming your node as a group in it's config, you can get reference to the base through that:
const group = RED.nodes.getNode(config.group)
const base = group.getBase()
Then in the relevant place after you've added the relevant properties:
The other thing you could do is fire a manual widget-load:<widget-id> event - which would fire the same logic client-side as when the widget is first loaded?
Just to add, that if you do set a new listener in the client-side widget (vue), you need to clear it in your unmounted() function:
unmounted () {
/* Make sure, any events you subscribe to on SocketIO are unsubscribed to here */
this.$socket?.off('widget-load:' + this.id)
this.$socket?.off('msg-input:' + this.id)
this.$socket?.off('custom-event:' + this.id)
},