23
Views
5
Comments
Solved
IsDirty state management problem
Application Type
Reactive

Hi everyone!

I have a popup that contains multiple blocks. One of these blocks (the target block) needs to know whether any other block inside the popup is dirty. I tried using events in each block to notify the popup when a block becomes dirty, and then passing this information to the target block through Input Parameters. 

However, I ran into a problem. The target block has an OnParametersChanged client action that refreshes its aggregates. When the aggregates refresh, they update some local variables - but this should not happen when only the IsDirty input parameter changes.

My goal is to let one block inside the popup know if any other block in the same popup is dirty, without triggering an aggregates refresh.

What would be the best solution to this problem?

2023-10-16 05-50-48
Shingo Lam
Solution

If I understand correctly, let summarize your case as below:

  1. popup contains many blocks: A B C D
  2. target block is A
  3. when changing B / C / D, A must be notified it is dirty
  4. A has OnParameterChanged that will refresh the data

My first solution is easy but not clean and general. You can do these amendments in block A

  1. use the local variable to store the data 
  2. OnAfterFetched of the aggregate: check the local variable has data, don't assign anymore, else assign
  3. OnParameterChanged: check the local variable has data, don't refresh, else refresh

For some additional purpose, can change the logic of OnAfterFetched and OnParameterChanged to let it refresh the data.


Second solution is cleaner one:

  1. in popup, define local variable to store: isDirtyB, isDirtyC, isDirtyD to determine which one is dirty.
  2. in popup, assign local variables by the event handler input when the dirty state of the block changed
  3. in block A, define the same input parameter to know which input one is dirty.
  4. in block A, define local variable to store: isDirtyB, isDirtyC, isDirtyD to determine which one is dirty.
  5. in block A > OnInitialzed, assign local dirty variables by dirty input parameter.
  6. in block A > OnParameterChanged, check the 3 dirty input parameters changed, don't refresh data, else refresh data  



2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @Łukasz Kaproń ,

Your target block has several inputs, some are indicators if other blocks are dirty, some are inputs that the blocks aggregates are based on, right ?

The simple approach is to make a local copy in targetblock of the input(s) that should trigger a refresh, and in OnParametersChanged check if local(s) <> input(s), in that case refresh aggregate and copy to local.

I have written an article if this simple approach leads to too ugly logic, but if you only have to make a simple decision, to refresh or not to refresh, that would probably be overdone.  If you have a complex block landscape, and don't want to have to pass around states from one child to another through a parent, you could look at the end of that article, the change locale example.

Dorine

2023-04-22 06-16-51
Vignesh Maliyekkal

Hi,

If I understand correctly, you’re retrieving the IsDirty value in the target block, but that action is triggering a refresh of the aggregate which you want to avoid.

If the goal is simply to prevent the aggregate from refreshing when IsDirty is true, you can add an If condition OnParameterChanged. When IsDirty is true, the logic will follow the alternative path and the aggregate will not be refreshed.

Hope this helps.

Regards,

Vignesh

2021-09-06 15-09-53
Dorine Boudry
 
MVP

Simply checking on IfDirty = true will probably not cut it. Once it becomes true, any future changes on the input that should trigger a refresh, won't.

2019-01-07 16-04-16
Siya
 
MVP

@Łukasz Kaproń :  You can apply the same solution discussed at https://www.outsystems.com/forums/discussion/105669/trigger-a-child-block-action/#Post464284 here as well.  You need to expose a method from the target block and when the popup receives events from the other blocks you invoke the exposed method. This way you will not refresh the aggregate.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.