mini-swift icon indicating copy to clipboard operation
mini-swift copied to clipboard

RxSwift to Combine translation

Open alejandro-ruiz-ts opened this issue 4 years ago • 0 comments

PR's key points

RxSwift to Combine translation of the FLUX architecture contained in Mini. The goal is to implement a Mini with the native reactive iOS library called Combine that can be used in a native reactive application with SwiftUI (or even with UIKit). To do this, these changes have been made to the following Mini core files:

  • Action.swift: the Action protocol remains the same, it does not depend on RxSwift.
  • ActionReducer.swift: the Reducer class will now inherit from Cancellable instead of Disposable. Its dispose() method is replaced by the cancel() method.
  • Dispatcher.swift: the DispatcherSubscription class now inherits from Cancellable instead of Disposable. Its dispose() method is replaced by the cancel() method.
  • Middleware.swift: the Middleware logic remains the same, it does not depend on RxSwift.
  • ReducerGroup.swift: the GroupReducer protocol and its variable disposeBag will now be of type Cancellable. The disposeBag will be an array of Cancellables. The dispose() function is replaced by the cancel() function.
  • Service.swift: the Service protocol remains the same, it does not depend on RxSwift.
  • State.swift: the StateType protocol is now a simple basic protocol that allows us to differentiate and group the State classes of our application, nothing more. In Combine the State must be classes unlike before, which were Structs. This is so because only classes can inherit from ObservableObject, whose functionality thanks to Combine will now allow us to listen to state changes.
  • Store.swift: this class now consists of a State of type ObservableObject and a StoreController of type Cancellable. The ObservableObject of Combine will be the one that will allow us to subscribe to the changes that occur in that state. This allows us to get rid of all the extensions and functions dedicated to listen to the states that we had when we depended on RxSwift. In the same way, Cancellable will be the new Disposable of our application. The code of the class has been quite reduced and clear.

Regarding the rest of Mini's content:

  • Utils: prematurely, during the study of the original Mini to try to understand and know how everything works, we started by translating the operator extensions contained in ObservableType+Extensions.swift from RxSwift to Combine. Although they are not ultimately needed within a project that uses Combine+SwiftUI, the native library provides the same operators. All other classes in this directory remain the same, they do not depend on RxSwift.
  • MiniTasks & MiniPromises: these two modules are still pending to be translated into Combine, specifically their PrimitiveSequenceType extension. They are not strictly necessary for the architecture of a SwiftUI+Combine project. The code has been commented and marked as TODO.
  • TestMiddleware: remains the same as it does not depend on RxSwift.
  • LoggingService: remains the same as it does not depend on RxSwift.

Regarding the package.swift file for package configuration:

  • Dependencies and targets that referenced the RxSwift and RxOptional libraries have been removed.

This new MiniCombine has been tested and verified in a project with FLUX architecture using the Assembler and dispatching actions to the stores. Its performance is correct and similar to what we had with MiniRxSwift.

How to review this PR?

alejandro-ruiz-ts avatar Jun 30 '21 10:06 alejandro-ruiz-ts