Just wondering if anyone has come across this very conundrum.
I define a custom event logic in the global canvas of my app (by the book).
Then I trigger this event in some other page of the same app.
The event, when received, sets a global app variable to a value.
This global app variable is bound to a 2-way property of a composite component.
Assigning a value to a 2-way property triggers an internal event in the composite component.
But the internal event is triggered twice!
any ideas? cc: @Kirill_Leventcov
Let me simplify the description of the problem.
I use a Collapsible grouped thumbnail list widget.
And I want to be able to refresh the widget data dynamically based on some external event (thus not using the data refresh polling logic offered by the widget);
The widget offers a number of built-in events, for instance an event is triggered if any internal property of the widget has changed.
Thus, I decided to have the RefreshRate property as a 2-way property.
Then, I bound the 2-way RefreshRate with a global app variable called reloadData
Whenever I set the reloadData to a new value (a randomly generated integer value) it should trigger an internal event.
Well, the event is triggered, but the event is triggered twice! and ALWAYS TWICE.
To summerize the question is: Why changing a value of a 2-way property generates this property’s internal change event twice ?
OK. I managed to solve this conundrum. It looks like the internal events of composite widgets have a global scope.
Thus, having 2 instances of Collapsible grouped thumbnail list widget, albeit in different pages, would result in generating an internal event for every Collapsible grouped thumbnail list widget instance where the internal 2-way property has been bound to one single global app variable.
And with 2 instances of the widget I was getting the event TWICE!.
Whether this behaviour is correct and/or by design, that I do not know. (albeit my gut tells me it is likely an expected behaviour as the events seem to have global scope but local visibility)
Long story short:
In order to address it I have now two separate 2-way property in Collapsible grouped thumbnail list widget and 2 separate global app variables. And the binding is done only for one of the properties in a given page or context.
This way the change event is triggered only once.
Mabye just try adding a debounce flow from the marketplace between the event received and your logic. Set the debounce to trigger on start, and not trigger on end and a timeout of 500ms.
That would result in only one firing after the debounce. And skipping every other inbetween the first and timeout value.
Thanks for the hint. But that would not work. The events including the internal ones have global scope so they get triggered for all instances of a given widget globally and not only in the context of the current page.
The solution I devised and described is working very well without any side effects.
As a result I got event-driven data refresh of my widget data in a context decided by the end user.