ReSwift port to Kotlin

Created on 9 Aug 2017  路  11Comments  路  Source: ReSwift/ReSwift

Hi guys,

I have implemented the port of ReSwift to Kotlin. GeoThings\ReKotlin

Obviously, our goal here is to have Kotlin port corresponding to ReSwift as closely as possible, so that everyone implementing both iOS and android apps have as smooth sail as possible.

Few differences exist though:

Dereferencing subscribers will not result in subscription removed

In ReSwift when you dereference the subscriber or it goes out of the scope, you won't receive new state updates.

var subscriber: TestSubscriber? = TestSubscriber()
store.subscribe(subscriber!)
subscriber = nil

However in ReKotlin you need make sure you have unsubscribed explicitly.

val subscriber = TestSubscriber()
store.subscribe(subscriber)
store.unsubscribe(subscriber)

Because of this thing, I had to ignore testStrongCapture() and testRemoveSubscribers() in unit tests.

Equatability and skipRepeats

When subscribing without substate selection like store.subscribe(someSubscriber) in swift you need to have your state implementing Equatable in order to skipRepeats being applied automatically.

public struct State: StateType {
    public let mapState: MapState
    public let appState: AppState
}

extension State: Equatable {
    public static func ==(lhs: State, rhs: State) -> Bool {
        //...
    }
}

However in Kotlin(JVM) every object implements equals(), so that skipRepeats will be applied automatically when you store.subscribe(someSubscriber), with Kotlin Structural Equality check used.

In terms of implementation I tried to keep as close as possible to original source. The only notable difference is the fact that kotlin supports parametrized interface types that avoid the need of type erasure.

__Please take a look and let me know your thoughts! Any suggestions or contribution is highly appreciated.__

There are more work on the roadmap. Over the next few weeks I hope to get done with:

  • [ ] port all docs
  • [ ] ReSwift Router port
  • [ ] ReSwift Recorder port
  • [ ] Advanced examples.

Most helpful comment

Wow, this is great, please list the pending works in roadmap, happy to contribute

All 11 comments

Wow! Will take a look!

That's an interesting and educational spin! Great!

Wow, this is great, please list the pending works in roadmap, happy to contribute

@Ben-G @mjarvis @DivineDominion @ambientlight can we move GeoThings/ReKotlin to this organisation? As its purpose is to create a port of ReSwift to Kotlin, I think it belongs here. Me and my team are considering using a combination of ReSwift and ReKotlin in near future apps and it's much easier to motivate others on my team if the ReSwift organisation takes ReKotlin under its wings. I think ReSwift will leverage its popularity if it has a Kotlin port.
I'm working on a port of ReSwift-Router to Kotlin with ReKotlin in mind (and I think others are too) and if we start using ReSwift and ReKotlin in real production apps, we will contribute to both libraries for at least a couple of years from now...

@hlineholm it has been moved into it's own organization - https://github.com/ReKotlin

However, I haven't yet added any a notice in https://github.com/GeoThings/ReKotlin. (Will do that asap)

@ambientlight great!

@hlineholm I understand why one would want ReKotlin to live under the ReSwift banner, but it would also create an assumption that the ReSwift team would be involved in its maintenance & updates, which we are unable to do (even giving ReSwift the time it needs is difficult).
I think I'd reconsider my opinion on this matter if/when ReKotlin grows its own community & maintainers, and is able to keep pace with ReSwift changes. At that time I think bringing them together might be beneficial.

@ambientlight It may be too late now, but Github does have "Transfer repository" support, which would cause the initial repo to redirect.
I think now you'd need to delete the new repository, then go to the old one, Settings -> Options, then scroll all the way to the danger zone.

@hlineholm We have the port of ReKotlin-Router here, it is in preview stage and we are using it already in some apps. Feel free to contribute.

It may be too late now, but Github does have "Transfer repository" support, which would cause the initial repo to redirect.

@mjarvis our company's decision was to keep the original repository under our organization, though my original through was the same as you suggested.

another thing is that I am no longer developing/maintaining our internal project that ReKotlin was originally written for though I hope to improve on contribution when I'll get some more spare time in several month from now

There was neither progress on ReKotlin nor on this issue, so I'm closing it for now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

patientplatypus picture patientplatypus  路  5Comments

krema picture krema  路  6Comments

steve21124 picture steve21124  路  11Comments

nferruzzi picture nferruzzi  路  10Comments

dolanmiu picture dolanmiu  路  6Comments