mini-swift
                                
                                 mini-swift copied to clipboard
                                
                                    mini-swift copied to clipboard
                            
                            
                            
                        RxSwift to Combine translation
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- Cancellableinstead of- Disposable. Its dispose() method is replaced by the cancel() method.
- Dispatcher.swift: the- DispatcherSubscriptionclass now inherits from- Cancellableinstead of- Disposable. Its- dispose()method is replaced by the- cancel()method.
- Middleware.swift: the- Middlewarelogic remains the same, it does not depend on RxSwift.
- ReducerGroup.swift: the- GroupReducerprotocol and its variable- disposeBagwill 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- Serviceprotocol remains the same, it does not depend on RxSwift.
- State.swift: the- StateTypeprotocol is now a simple basic protocol that allows us to differentiate and group the- Stateclasses of our application, nothing more. In Combine the- Statemust be- classesunlike 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- Stateof type- ObservableObjectand a- StoreControllerof type- Cancellable. The- ObservableObjectof 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,- Cancellablewill be the new- Disposableof 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.swiftfrom 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 PrimitiveSequenceTypeextension. 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?
…