Xamarin.Forms with Redux (part 1)
Toni Petrina
192

Toni Petrina How do you handle Immutable state using YAXL.Redux ? I did not try a lot but I suppose you have at least two options : 1) is to use struct but it is a lot more difficult to handle sub-properties or 2) using ReadOnly<T> and so it needs a lot of tooling like shallow copy and everything else that can help you to update the state without effort. May have you the solution?

Anyway, I tried it on a UWP application and it really gives a lot of flexibility. I avoided the use of ViewModels so I could update the UI directly from the code-behind. The UI part of the ViewModels is now less reusable but I prefer the separation AppState/UI than MVVM because whatever the user do is an action (similar to command in MVVM) and then the UI is purely updated based on the content the State. And so, the XAML part does not have any knowledge of the (dynamic) data because it is entirely driven by the code-behind.

And last but not least, I don’t know if it is a maintainable solution but my actions are not reduced by a string but the Type of the action. Here is an example using C#7 features:

```
if (action is IncrementAction incrementAction)

 state += incrementAction.Value;
}
if (action is DecrementAction decrementAction)

 state -= decrementAction.Value;
}
return state;
```

Like what you read? Give David Bottiau a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.