Comments (7)
Alright, I think we see this differently. From my PoV it's irrelevant what alters the state.
showing a loading spinner is exactly the same thing as setting a list of tasks.
They both update the UI that's subscribed to the state.
But I'll just maintain this notion myself! Thanks for the code example on canceling, that's useful!
from reactorkit.
In that case it's recommended to use both Action
and Mutation
. Action is just an abstraction of an user input from a view and a mutation is a state-manipulator.
enum Action {
case requestTasks
}
enum Mutation {
case setLoading(Bool)
case setTasks([Task])
}
func mutate(action: Observable<Action>) -> Observable<Mutation> {
switch action {
case .requestTasks:
return Observable<Mutation>.concat([
Observable.just(.setLoading(true)), // .setLoading(true)
fetchTasksUsingAPI().map { Mutation.setTasks($0) }, // .setTasks([...])
Observable.just(.setLoading(false)), // .setLoading(false)
])
}
}
You may refer to the actual code: https://github.com/devxoul/Drrrible/blob/f52812943d16a891ace62083adac753c2c30ac87/Drrrible/Sources/ViewControllers/ShotListViewReactor.swift#L44-L53
from reactorkit.
Yes, I understand that part. The problem is you're gong to get a lot of messy actions that don't do anything they than toggling visibility of components. Setting the loading spinner is part of loading the tasks. Not two different actions. Except one mutation is async and the other synchronous.
from reactorkit.
Btw, I figured out a way to handle the infinite loop problem That Redux-Observables have. Ensure type constraints on your "epic". T: Action -> U:Action
where T != U.
That solves the :
"const actionEpic = (action$) => action$; // creates infinite loop"
from reactorkit.
Setting the loading spinner is part of loading the tasks. Not two different actions.
There's one action and two mutations. It's not "two different actions". One action can occur multiple mutations.
And I didn't see anywhere that occurs infinite loop in ReactorKit. Could you reproduce it?
from reactorkit.
@devxoul No, the infinite loop is part of Redux-Observable issue :) not related here, sorry for the confusion!
Yeah but why does setting loading need its own action? As far as I see, those two things are related. There are other cases where you'd want an action to reduce state and async trigger a different action.
I really suggest looking into Redux-Observable, the strength comes from the ability to cancel async actions. https://redux-observable.js.org/docs/recipes/Cancellation.html
from reactorkit.
Why do we have to expose an Action.requestTasksCompleted
to a view? A view's interest is just an Action.requestTasks
. Action and Mutation are different. Action just takes user inputs from a view and Mutation just manipulates the state. Their role are different from each other. Of course the Action.requestTasks
and setLoading
can be related but "setting loading" is not a role of an Action. I would like to separate the responsibility to reduce complexity.
And for cancellation, I think we can make actionSubject
public. It may look like:
func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .refresh:
return Observable<Mutation>.concat([
Observable.just(.setLoading(true)),
API.requestTasks()
.map { Mutation.setTasks($0) }
.takeUnil(self.actionSubject.filter(Action.cancelRefreshing)),
Observable.just(.setLoading(false)),
])
}
}
I'll take a look at this for another solution 👀
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.