Comments (5)
you need to subscribe to it so it is not disposed/deallocated right away.
from reactorkit.
@zdenektopic you mean it needs to subscribe to Action?
from reactorkit.
-
I didn't understand 'triggering the Action without subscribing to State'. Could you please share me some detailed situation?
-
You should always return Observable from
mutate()
. Returning.empty()
is also my preferred way but it would be better to use like:return Observable.create { [weak self] in self?.userService.appendKey(key) return Disposables.create() }
from reactorkit.
@devxoul Thank you.
Scenario
I used ReactorKit and realized that my actions really work when I subscribe to the State.
For example:
I have UI components bound to some action in my Reactor
self.button.rx.tap
.flatMap { self.textField.rx.text }
.map { Reactor.Action.appendElement($0) }
.bind(to: reactor.action)
.disposed(by: disposeBag)
where Action
:
enum Action {
case appendElement(String)
}
and in mutate(action: Action)
function, I have only one Side Effect where I save my element into the disk. But it doesn't work. Even break points don't work unless I create Mutation
and State
for this case and I subscribe to the State
in my View
, like this:
reactor.state.map { $0.element }
.subscribe { print($0) }
.disposed(by: disposeBag)
After all of that, I can see how break points stop in mutate(action: Action)
and function works.
Question
How can I bind my UI components toAction
without creating any Mutation
& State
?
from reactorkit.
Ah, I got it. You may want to create a state stream without binding it to the view. Try this:
class MyReactor {
init(params: MyParameters) {
self.initialState = State(foo: bar)
_ = self.state // add this line to create a state immediately
}
}
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.