Comments (5)
Ok.
What I feel when looking at ReactorKit is that I am somehow missing the ViewModel. Reactor as by name already reminds of something that is yet behind the view model and controls all the tasks like networks requests/services etc.
from reactorkit.
Global state management is not a ReactorKit's responsibility. So you can use anything to manage the synchronisation. For example, you can use a global Subject
to store synchronisation process or you can even use Reactor
as a global synchronisation state manager. The important thing is that every Reactor can observe the global state and update its state.
Let's assume that we have a sync state as a Variable
.
SyncState.swift
struct SynchronisationState {
var usernames: [String] // example properties that will be binded to table view
}
let syncState = Variable<SynchronisationState>(SynchronisationState(usernames: []))
AppDelegate.swift
func applicationDidBecomeActive(_ application: UIApplication) {
Synchroniser.sync() { newState in
syncState.value = newState // emit a synchronised state
}
}
MyViewReactor.swift
class MyViewReactor: Reactor {
enum Action { ... }
enum Mutation {
case setUsernames(String)
}
struct State {
var usernames: [String]
}
// Merges two observables into a single observabe:
// 1. Mutation observable from Reactor
// 2. Mutation observable from global `syncState`
func transform(mutation: Observable<Mutation>) -> Observable<Mutation> {
let fromSyncState = syncState.asObservable()
.map { $0.usernames }
.map { Mutation.setUsernames($0) }
return Observable.merge(mutation, fromSyncState)
}
func reduce(state: State, mutation: Mutation) -> State {
switch mutation {
case let .setUsernames(usernames):
var newState = state
newState.usernames = usernames
return newState
}
}
}
from reactorkit.
I see. So I should also transform and map the data as they are supposed to go to view? Does Reactor also poses as ViewModel
then?
What about transitioning between data? Like UITableView
s beginUpdate
, insertRows
etc?
from reactorkit.
@zdenektopic, You can directly map the global state to the View but it's recommended to use Reactor for testability. It's true that a Reactor it similar to a ViewModel because ReactorKit was originally started from MVVM.
If you're using RxDataSources you just can use RxTableViewSectionedAnimatedDataSource
or RxCollectionViewSectionedAnimatedDataSource
for animated updates. Otherwise you can use beginUpdate()
and endUpdate()
.
from reactorkit.
Please reopen it if you have further questions :)
from reactorkit.
Related Issues (20)
- Reactorkit
- Build Failed since Xcode 12
- Xcode 12 : PR 163 & WeakMapTable bug HOT 6
- Xcode 12 Build Error WeakMapTable target 8.0 error HOT 2
- Build Failed since Xcode 12 Using Swift Package Manager HOT 2
- bind method Each request is called HOT 1
- ReactorKit+RxViewController inherit StoryboardView Error HOT 5
- Cartfile Issue
- compatible HOT 1
- WeakMapTable
- Freezing occurs when running iOS app in MacBook (M1 process) HOT 1
- Build error "Value of type 'Reactive<SplashViewController>' has no member 'viewDidAppear'" HOT 1
- How to handle global state? HOT 2
- Is there a better way to generate sections?
- OC Version request
- Do you support SPM officially? HOT 1
- one attribute bind another attribute in same reactor HOT 1
- View is ambiguous type. Clash between SwiftUI public protocol and ReactoriKit's public protocol. HOT 3
- Just a Question
- How to sync the state to tableView from Cell? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactorkit.