reduxkotlin / Reselect

A selector library for ReduxKotlin
Apache License 2.0
1 stars 3 forks source link

JS Reselect dissimilarities #5

Open jason-whitted opened 4 years ago

jason-whitted commented 4 years ago

The redux-kotlin and redux-kotlin-thunk libraries are pretty much clones of their JS counterparts. However, in addition to this library currently not working, it is also very disjointed from JS Reselect.

Reselect does not require redux, it just happens to be extremely useful with it. The SelectorSubscriberFn<AppState>(store) method implies that Reselect is coupled with redux. The withSingleField and withSingleFieldByValue syntax also has no counterpart in Reselect.

I have been playing around with a library that mimics reselect as much as possible.

Here's an example of my library:

// Test case models
data class State(val person: Person)
data class Person(val name: Name, val age: Int)
data class Name(val first: String, val last: String)

// Selectors
val selectName = createSelector<State, Name> { it.person.name }
val selectFirst = createSelector(selectName) { it.first }
val selectLast = createSelector(selectName) { it.last }
val selectFullName = createSelector(selectFirst, selectLast) { first, last -> "$first $last" }

@Test
fun shouldWork() {
    val state = State(Person(Name("Bob", "Smith"), 42))
    val fullName = selectFullName(state)
    assertThat(fullName).isEqualTo("Bob Smith")
}

It's also properly memoized at various depths -- similar to JS Reselect.

If you are at all interested in the code, let me know. I'd much rather support an existing OSS project than confuse the ecosystem by publishing another similarly named product. If this was not the intended direction of this repository then I understand that as well.

patjackson52 commented 4 years ago

Thanks for the feedback. This does need some attention. Originally this goal of this was to serve the same purpose as Reselect with redux, not clone the JS version. It also was forked from another project as a quick way to get something together. Perhaps naming this repo something other than 'Reselect' would be helpful.
I have some local work that I haven't merged into this repo yet that I've found helpful and more kotlin friendly. I'd like to get that pushed up this week and I'll tag you when I do.

The above looks interesting too. Maybe after I push up my PR we can discuss future direction and what we want out of this library. Any other opinions are welcome too.

sjmueller commented 4 years ago

@jason-whitted i am interested in working code if you have some available! We are coming to jetpack compose + redux from SwiftUI + Reswift and subscribing to a substate of the store is critical.

jason-whitted commented 4 years ago

@sjmueller I don't want to spam this repository with links to mine. But if you go to bintray and search for kotlin-redux, kotlin-redux-reselect, or kotlin-redux-thunk from groupId com.github.etalisoft you should be able to find it.