-
Notifications
You must be signed in to change notification settings - Fork 212
Closed
Description
For example, I have the following nested state (only left the relevant parts for clarity):
class AppState {
final OpenBook openBook;
}
class OpenBook {
final bool headerIsFetching;
}
And the reducer:
new AppState(
openBook: new OpenBook(//<- This can be optimized! new instance is built for every cycle regardless of the action
headerIsFetching: buildFetchingReducer<FetchOpenBookHeaderAction, FetchOpenBookHeaderSucceededAction, FetchOpenBookHeaderFailedAction>(state.openBook.headerFetching, action)
)
);
I have thought 2 options:
- Encapsulate the instantiation of the OpenBook inside an if that tests for the relevant actions, but this leads to code duplication and it goes against the Open/closed principle (SOLID)
- Use a switch and for each relevant action create a new OpenBook and initialize only the relevant property, but it feels weird as Dart doesn't have the Spread operator (the three dots in javascript)
- Flatten the state
Do you have a recommendation?
Metadata
Metadata
Assignees
Labels
No labels