I have a webblock that has an OnChangedParameters handler. In an action in the parent webblock of this webblock, I have an action that changes one of the input parameters of the child webblock and directly after it in the same flow I have a JavaScript node that triggers an action also inside of the child webblock.
I am finding that the JavaScript runs the action inside of the child web block before the OnParametersChanged of the child webblock runs. I thought this would not be the case since I thought the OnParemetrsChanged would trigger as soon as that input changes - which is just before the JavaScript is meant to run. Or does the OnParametersChanged wait till the current action is finished perhaps before executing?
What I would like to know is if this current order of actions is expected and if so why? Or if it is just a coincidence based on timing and sometimes the one will run before the other and sometimes it will be the other way around - which would be bad since it would be inconsistent and affect the logic.
see attached oml, (the SomeScreen screen) demonstrating :
that all DOM changes are postponed until all actions are done : the screen DOM value of the variable is not updated, even at the end of the OnParametersChanged of the webblock. Further proven by the OnRender of both block and screen only happening after the blocks OnParametersChanged.
that the inputs of the block are only updated AFTER the screen action that is changing the source variable is completed. At end of screen action, the screen variable already has the new value, but when we spy into the webblock at that point (see "how is it hanging", the input variable it is passed into still has the old value, only getting the new value in the OnParametersChanged event.
I imagine the rationale behind this, is that variables can change several times during an action, and you only want effects of the change to happen after final value is reached. As is demonstrated in the 'Change and change back' test, where the OnParametersChanged of the block is never called.
Dorine
Hi @Nicholas Campbell ,
Or can you share an oml demonstrating the problem ?
Now on design, the appropriate way for a parent screen to trigger behaviour in a child webblock is through the OnParametersChanged event. Could you not move whatever you trigger in that javascript to the OnParametersChanged event ?
I find it very ugly to dig into the inner workings of a webblock under water like that, it destroys any separation of concerns the webblock was providing.
Hi Dorine
Good idea to use some pauses etc to figure that out. And thanks for providing such an example - I will look into it and respond to your second message later - but from your response, I can already see the answer to my question which is very helpful - that the OnParametersChanged is only triggered after the screen action changing the variables is finished. As for your first message:
The JS is calling actions exposed by the web block using JS. I am using this approach because the OnParametersChanged method can become very complicated and convoluted depending on what needs to be communicated from parent to child - especially in complex situations. Hence exposing the actions via the DOM makes things a lot simpler and neater.
Hi,
I am also sometimes struggling with the compactness of having to organize all communication from parent to block through one and the same OnParametersChanged event of the block.
One of the things I came up with to be able to split this logic into separate actions, each firing only if stuff they are interested in has changed, is to make a helper block that looks at only part of the complex block's inputs, and fires an event to be handled in the complex block by a specific action that is interested in changes to that subset of inputs.
See attached oml for a demo of this idea.