https://kotlinlang.org logo
Join SlackCommunities
Powered by
# redux-kotlin
  • p

    pardom

    10/10/2016, 8:50 PM
    Yes. Elm Architecture and Redux are essentially the same.
  • p

    pardom

    10/10/2016, 8:50 PM
    In fact, the Redux docs cite Elm Architecture as an inspiration.
  • g

    gnardini

    10/10/2016, 8:50 PM
    Yup, just a few differences
  • p

    pardom

    10/10/2016, 8:55 PM
    And W.R.T. your question about the toast, I suppose you could have an action
    ShowToast(val text: String)
    that would copy a
    toastText: String
    value to the state.
  • p

    pardom

    10/10/2016, 8:55 PM
    And on every other action, clear
    toastText
    .
  • p

    pardom

    10/10/2016, 8:56 PM
    Or… your view could provide a custom middleware that listens for
    ShowToast
    actions.
  • p

    pardom

    10/10/2016, 8:57 PM
    Then you wouldn’t need anything in your reducer or state.
  • p

    pardom

    10/10/2016, 8:57 PM
    Probably the approach I would take is the same for navigation
  • p

    pardom

    10/10/2016, 8:58 PM
    In my view controller/presenter/model, I inject an interface
    NavigationService
    and
    NavigationFactory
  • p

    pardom

    10/10/2016, 8:58 PM
    So when I send a
    GoBack
    action, my custom middleware will call
    navigationService.goBack()
  • p

    pardom

    10/10/2016, 8:59 PM
    Then the frontend (Android, Desktop, etc) provides the implementation of
    NavigationService
    .
  • p

    pardom

    10/10/2016, 8:59 PM
    You could have a
    ToastPresenter
    which does the same
  • p

    pardom

    10/10/2016, 9:04 PM
    @User uploaded a file: Untitled and commented: Like this
    -.kt
  • p

    pardom

    10/10/2016, 9:04 PM
    Here’s a real-world example using `NavigationService`: https://github.com/pardom/CleanNews/blob/master/presentation/src/main/kotlin/clean/news/presentation/model/item/ItemDetailViewModel.kt
  • g

    gnardini

    10/10/2016, 9:56 PM
    I see, I hadn’t though about the presenter approach, that was really helpful. My only concern is that the middleware in that case is not a pure function, which I’m not so sure about it being a good practice. It does make the state cleaner though, and clearing the
    toastMessage
    from the state on every reduce call isn’t ideal either. I’ll give it a try and see how it works out, thanks!
  • p

    pardom

    10/10/2016, 10:22 PM
    I/O obviates purity. The toast can be considered I/O, so I would consider it to be pure, but I could be wrong.
  • g

    gnardini

    10/10/2016, 10:24 PM
    Yeah, that's a good point
  • p

    pardom

    10/10/2016, 10:27 PM
    Although, you're right that it's technically not pure, because the ToastPresenter is out of scope.
  • k

    kittinunf

    01/03/2017, 3:10 AM
    @kittinunf has left the channel
  • m

    mesquka

    04/26/2017, 2:24 PM
    @mesquka has left the channel
  • a

    Archie

    07/29/2020, 1:36 PM
    This channels seems to be inactive for a long time now but Im starting to learn Redux Architecture in Kotlin and theres one thing I don't know how to start so I'm gonna shoot my shot and hopefully someone answers. 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:
    Copy code
    data class AppState(
        val loginAppState: LoginAppState,
        val signUpAppState: SignUpAppState
        val someOtherScreenAppState: OtherScreenAppState
        ....
    )
    
    data class LoginAppState(
        val usernamer: String,
        val password: String
        ....
    )
    I'd really appreciate any help. Thank you very much in advance
    v
    w
    • 3
    • 3
  • d

    Davide C

    03/31/2021, 11:00 AM
    Hi! In a multiplatform project (mobile) it's feasible to use ReduxKotlin with JetpackCompose on Android side? I had a look to the MoviesSwiftUI project with no luck, sadly I'm not able to compile with my current setup. Are there any updated examples? Thanks
    j
    • 2
    • 1
  • s

    Stefan Oltmann

    07/27/2021, 6:51 AM
    Since I'm new to the MVI/Redux style I wonder: Given my app shows a welcome screen on first run to ask for users consent in Crashlytics, are the boolean states "firstRun" and "crashlyticsEnabled" (which I will store as SharedPreferences) also part of my "AppState" object or is that something else? And bonus question: What does that mean for preferences in genreal? Is everything a user might set there also part of my state object? It controls if the checkbox is ticket or not for the UI, so I would guess tho...?
  • w

    William Persall

    09/02/2021, 9:25 PM
    I am having issue creating a store. The Store requires the first argument to follow the
    type alias Reducer<S,A> = (S,A) -> S
    When I create function that looks like
    fun myfun(State:SomeStateClass, action:Action):SomeStateClass
    Then I get a mismatch type error on myFun when entered as below.
    val store = createStore(myFun(), SomeStateClass())
    is this a know issue, or is there a workaround?
    g
    • 2
    • 2
  • w

    William Persall

    09/17/2021, 2:29 PM
    I have been googling to find how to get redux dev tools to work with my multiplatform fullstack web project. Only thing I found was akjaw.com kotlin/js react,redux witj thunk tutorial Unfortunately, the js function in the compose statment doesn't seem to be allowing gje browser to recognize the store. It comes across as undefined in the redux tool extension for Chrome. Has anyone gotten this to work?
    b
    • 2
    • 6
  • a

    Alexander Black

    01/08/2022, 12:59 AM
    I'm wondering if anyone has advice on how to do Async Actions where the dispatch ordering is always sequential? I wrote a request middleware
    Copy code
    override fun invoke(store: Store<AppState>): (next: Dispatcher) -> (action: Any) -> Any {
            return { next ->
                { action ->
    
                    if (action is Request) coroutineScope.launch {
                        action.execute(store.getState, store.dispatch, api, db)
                    }
    
                    next(action)
    
                }
            }
        }
    which just dispatches async requests on its own coroutineScope which is very useful for making API/DB fetches, but the problem I run into from time to time is if I want to update the store state and then dispatch another action from within an action sometimes the state updating action gets executed after the next request action, which might depend on the state being updated. Maybe my approach is wrong, but that's kinda what I'm struggling with. example usecase: BootAppRequest: step one: get the logged in user data from the db step two: update the store with the user data step three: This step is new dispatched action. request some other user data from API which depends on user data being in the store. as you can see from the usecase above the sequence of actions is important. I could execute step three in a function, but it's being used in several places in the UI and for good code reusability it makes more sense to be a dispatched action. I really want the request action to get handled on a background thread so I don't potentially impact the UI thread Anyway any advice would be helpful.
    j
    • 2
    • 2
  • j

    Jasin Colegrove

    03/12/2022, 6:17 PM
    How do we use a rootReducer of return type AppState to create a store of type Reducer<AppState>. Site documentation is about as clear as mud.
  • c

    Claude Brisson

    03/24/2023, 7:03 AM
    As I understand it, state members do not necessarily need to be data classes themselves. The should at least be immutable (or treated so), and serializable in some use cases, but shallow copies of states should be OK, shouldn't they?
  • w

    William Persall

    05/12/2023, 6:22 PM
    I am using react wrappers with 18.2.0-pre.385 with react redux 7.2.6-pre-385. I am having issues getting the FC get state. I think it is because I don't have the provider method set up. The method extends from RBuilder, and doesn't seem to recognize a FC. Nor can I find documentation on how to use provider with create Root, as in should I wrapp create root render method in provider method or provider method wrapped in the create root render method. I wish there was more examples co located with the wrappers located
  • w

    willyrs

    02/09/2024, 5:05 PM
    What's the best way to inject the context into a Middleware?