tim
04/10/2020, 9:49 AMstate.copy(levelOne = levelOne.copy(levelTwo = levelTwo.copy( value = 0 )))
which may not seem too bad here, but does get quiet verbose when I'm trying to update several values at two different 'paths'. Additionally I need to get/set values dynamically (think lodash's set/get functionality) i.e., get<T>(state, "levelOne.levelTwo.value)
and set(state, "levelOne.levelTwo.value", 1)
. I should note my state is being serialised/deserialised to/from Firestore as a Map.
To accomplish the above, I'm converting my hierarchy of data classes to a map (with nested maps) using jackson, and then implementing the set/get functionality on those maps, before converting back to the original State data class hierachy. But this seems needlessly complex. For example, I have to convert everything in the specified update path to a mutable structure, transverse the maps, and do lots of casting along the way. But, the benefit is that nested access is straightforward and my reducers are simple:
reducer(state: State, action: FSA) {
val payload = action.payload
// I actually do this in my root reducer so i just mutate state directly here
val fresh = state.copy()
val oldValue = get<Int>("levelOne.levelTwo.value")
set(fresh, "levelOne.levelTwo.value", 3 * oldValue)
return fresh
}
I'm thinking one improvement I could do is implement something like immerjs where state is 'patched' in reducers and the patches are applied all at once before the root reducer finally returns the next state to minimise my converting to/from maps.
The friction here stopping me from going to Maps altogether, is with data classes I get type safety when reading most values from state normally ... val some = tate.levelOne.levelTwo.value
.
Grateful for your thoughts/objections to the approaches above 🙏Robert Jaros
05/12/2020, 10:34 PMPatrick Jackson
05/22/2020, 2:27 PMzalewski.se
06/13/2020, 3:26 AMPatrick Jackson
06/14/2020, 12:47 PMRobert Jaros
06/14/2020, 1:50 PMBig Chungus
06/14/2020, 3:01 PMAndrew Steinmetz
06/30/2020, 5:27 AMwillyrs
07/03/2020, 6:02 PMval splashReducer: Reducer<SplashState> = { state, action -> return state }
and when I call it on iOS I have a EXC_BAD_ACCESS (code=1, address=0x0) error
If I write the function like this:
fun splashReducer(state: SplashState, action: Any) : SplashState { return state }
it works!
Do you think it’s a problem with reduxkotlin or with kotlin-native?
P.S. On kotlin-android it works with bothPatrick Jackson
07/04/2020, 1:35 AMwillyrs
07/13/2020, 4:40 PMSamuel Bichsel
07/22/2020, 3:37 PMRobert Jaros
07/24/2020, 3:54 PMArchie
07/29/2020, 3:25 PMKotlin Redux
a few days back and now Im starting to learn and study it. I understand the concepts very well but I just can't get how to model the AppState
right.
How exactly do you model the AppState
? Examples I've seen so far only show a small application where the AppState
is very simple. But how do you model an AppState
in a Large Application with multiple screens? Do I make smaller "`AppState`" inside the "root" AppState
like:
data class AppState(
val loginAppState: LoginAppState,
val signUpAppState: SignUpAppState
val someOtherScreenAppState: OtherScreenAppState
....
)
data class LoginAppState(
val usernamer: String,
val password: String
....
)
It seems that Redux
makes sense when screens share state between screens such as the Todo Application Example or its very simple when dealing with single screen application such as the Counter Application but how do you model the AppState
when working with screens doesn't really have connected state such as an application with a LoginScreen
and SignUpScreen
. Those two screens doesn't share any state. How to deal with these kinds of scenarios?
I'd really appreciate any help. Thank you very much in advanceArchie
08/26/2020, 3:02 PMMark Iantorno
08/30/2020, 6:42 PMCorey Lanier
09/29/2020, 9:46 PMDenis Ismailaj
10/24/2020, 9:39 PMwillyrs
01/29/2021, 12:55 PMBrian Odisho
05/26/2021, 10:30 PMbabel
05/27/2021, 7:39 PMzalewski.se
07/01/2021, 5:35 PMWilliam Persall
09/08/2021, 7:40 PMPatrick Jackson
12/14/2021, 6:34 PMRobert Jaros
12/14/2021, 6:41 PMAlexander Black
01/08/2022, 5:35 AMDan Nesfeder
02/01/2022, 9:45 PMJoakim Forslund
03/03/2022, 11:46 AMfun subscribe(onChanged: (AppState) -> Unit):StoreSubscription {
return store.subscribe { onChanged(store.state) }
}
What would be the easieast way to make this more generic to listen to a specific state rather than the appstate? Obviously making each state inherit from a base class or interface is one way, but is there a more functional way?Philipp Nowak
05/30/2022, 2:11 PMPatrick Jackson
08/27/2022, 12:53 AMPatrick Jackson
08/27/2022, 12:53 AMRobert Jaros
08/27/2022, 6:32 AMBig Chungus
08/27/2022, 6:55 AM