impierce / identity-wallet

A Tauri-based Identity Wallet for people to manage Decentralized Identities and Verifiable Credentials.
https://www.impierce.com
Apache License 2.0
17 stars 4 forks source link

Make `state` parameter in reducers immutable again #163

Open nanderstabel opened 3 months ago

nanderstabel commented 3 months ago

Description

As introduced here: https://github.com/impierce/identity-wallet/pull/157#discussion_r1526166365

Several reducers currently have the following signature:

(mut state: AppState, action: Action) -> Result<AppState, AppError>

which need to be replaced with:

(state: AppState, action: Action) -> Result<AppState, AppError>

so that the incoming state is immutable.

instead of changing fields in a mutable state, a new state needs to be returned like this:

return Ok(AppState {
    field: changed_value,
    ..state
});

Motivation

Always safer/more idiomatic to keep the state as immutable as possible and only explicitly take ownership over specific fields in order to make them mutable. This will also be closer to redux pattern principles.

Resources

157

To-do List