I have a page with a data repeater containing a check box. So I end up with between zero and 5-ish checkboxes.
There is an On Change event handler that adds/removes data to Page Data when the boxes are checked/unchecked.
I want to be able to pass an id into the page, which matches one of the check boxes, and pre-checks that check that box. If I use the Checked State logic, it can have the box checked, but the On Change code doesn’t run. So the values aren’t put into Page Data.
It doesn’t seem efficient to replicate the code in On Change and Checked State. My ideas:
Custom JS code to simulate a click on the box to trigger the On Change event hander? Not sure this would even work.
Put the On Change event hander code into a function and call the function from the Checked State Logic?
Firing a fake event or duplicate logic into the Checked State handler is an absolutely wrong solution(also it may trigger a lot of rerenders).
You should process data separately when you already have your checkboxes list. It could be done in On Before Mount ... or On Mounted ... handlers - any what called once. In that case, we will have an actual state, and only update it in On Change events.
As for code duplication, you could create a custom function that will be called from the “initial calculation” and “On Change” events.