Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass a sealed class #22

Open
robert-cronin opened this issue Jan 25, 2019 · 1 comment
Open

How to pass a sealed class #22

robert-cronin opened this issue Jan 25, 2019 · 1 comment

Comments

@robert-cronin
Copy link

This is not exactly an issue, more of a documentation request as I couldn't seem to figure out how to do it just fiddling around.

I have a sealed class I am using as an action:

class SelectClient(var id:String? = "") {
    companion object
}

My reducer looks like this:

val rwaReducer = Reducer { state: RWAState, action: Any ->
    when (action) {
        SelectClient -> {
            val action = action as SelectClient
            println(action.id) // Doesn't print anything here
            state
        }
        else ->
            state
    }
}

When I dispatch an initialized class variable, it doesn't do anything in the reducer, looks like it doesn't recognize the class as the action passed

var action = SelectClient()
action.id = "SomeClient"
rwaStore.dispatch(action)

Perhaps I am dispatching wrongly? Any help would be appreciated! :)

@MairwunNx
Copy link

@robert-cronin you must replace

    when (action) {
        SelectClient -> {

to

    when (action) {
        is SelectClient -> {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants