Reswift: Derived State

Created on 7 May 2018  路  3Comments  路  Source: ReSwift/ReSwift

Does this library support "Derived State"?

Say I dispatch a User action, so my AppState now has User profile information

I would like state.isLoggedIn to automatically be there also without me manually having to set this .isLoggedIn property

@ngrx has this concept called selectors to do just this.

I am wondering if ReSwift has this?

Most helpful comment

I don't know the ngrx stuff, so I cannot compare. What I'd do is expose a computed property, like I'd do without ReSwift, too:

struct AppState: StateType {
    var userState: UserState
    var isLoggedIn: Bool { return userState.isLoggedIn }
}

struct UserState {
    var credentials: (String, UserID, UnsafePlainTextPassword)?
    var isLoggedIn: Bool { return credentials != nil }
}

All 3 comments

There is a library cal ReRxSwift which aims to connect state to props automatically like the connect function from react-redux

https://github.com/svdo/ReRxSwift

I don't know the ngrx stuff, so I cannot compare. What I'd do is expose a computed property, like I'd do without ReSwift, too:

struct AppState: StateType {
    var userState: UserState
    var isLoggedIn: Bool { return userState.isLoggedIn }
}

struct UserState {
    var credentials: (String, UserID, UnsafePlainTextPassword)?
    var isLoggedIn: Bool { return credentials != nil }
}

Am closing this because there was no activity for a while

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leizh007 picture leizh007  路  11Comments

Thurman1776- picture Thurman1776-  路  3Comments

dennisfarandy picture dennisfarandy  路  6Comments

patientplatypus picture patientplatypus  路  5Comments

nodediggity picture nodediggity  路  8Comments