Replies: 3 comments 6 replies
-
Can you explain a bit more about what you are trying to achieve? TCA's types are not thread safe, and so it is expected you always interact with them on the main thread. It's your responsibility to do that, and the library does not automatically enforce it for various reasons. |
Beta Was this translation helpful? Give feedback.
-
@mbrandonw Thanks for replying.
Yes, I understand that, and I am perfectly happen to maintain the thread manually.
What I want to achieve is, to assign a queue to a Something like (I am making this up): enum FooAction: Equatable, BindableAction {
- case setFoo(String)
case binding(BindingAction<FooState>)
}
var fooReducer: Reducer<FooState, FooAction, FooEnvironment> = .init { state, action, environment in
switch action {
case .binding:
return .none
}
}
+.binding { keyPath in
+ switch keyPath {
+ case .$foo:
+ return { foo -> Effect in
+ Effect(value: .set(\.$foo, foo))
+ .delay(for: 0.2, scheduler: DispatchQueue.main)
+ .eraseToEffect()
+ }
+ }
+} |
Beta Was this translation helpful? Give feedback.
-
Ok, if I'm understanding correctly, the real issue here is not so much that you want to execute something on the main queue, but that you want to delay updating your state from a binding by 0.2 seconds? If that is the case then yes you must use a separate action. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
For the example code below:
I want to force the mutation to
FooState.foo
on a specific queue, say theDispatchQueue.main
. I know I can achieve this by adding a proxy action like:But is there a way to avoid this redundancy of adding a specific action to do something that can already be achieved by the
binding
action, and apply theEffect
modifier like receiving on specific queue directly to it?Beta Was this translation helpful? Give feedback.
All reactions