Comments (12)
Think this can be closed now :)
from reactiveswift-composable-architecture.
@mluisbrown Related: pointfreeco/swift-composable-architecture#506
In order to throttle an effect's actions as they re-enter the reducer we think it's not possible to lean on existing publishers, similar to how Effect.debounce
must be defined and why we can't simply lean on Combine's debounce
operator.
from reactiveswift-composable-architecture.
What is your use case for this? Could you not just use SignalProducer.throttle
?
If you want it to be cancellable, you can always tack on .cancelable(id:)
to the operator chain.
from reactiveswift-composable-architecture.
why we can't simply lean on Combine's debounce operator.
I must be missing something, as I can't quite see why you couldn't just use Combine's debounce
and throttle
operators. There a couple of places in our project where we need throttling and we are just using the the standard Reactive Swift throttle
operator.
One reason I ported the Effect.throttle
operator (other than for the completeness of the port), was that unlike the Combine version, the Reactive Swift version doesn't support the latest
parameter. It always publishes the latest value.
btw, regarding the issue at hand, I have no problem with making Effect.throttle
public, particularly as it adds the latest
option which the RAS version doesn't have. I only haven't done so to be in sync with the main TCA repo.
from reactiveswift-composable-architecture.
Our API request Api.searchUsers(byUsername:)
returns only one result for one call. The existing Combine / ReactiveSwift debounces / throttles only repeated values for the call.
My case works so that it calls Api.searchUsers
each time user enters username, so that previous Api.searchUsers
is canceled and new called (this's how composable reducer works under the hood). So existing debounce / throttle just don't work.
As for example see part of my reducer is below. This example is already with throttle that is needed.
public let userSearchReducer = Reducer<
UserSearchState,
UserSearchAction,
UserSearchEnvironment
> { state, action, environment in
switch action {
case let .updateUsername(username):
guard let username = username, !username.isEmpty else {
state.users = []
return .cancel(id: SearchByUsernameID())
}
return environment.api
.searchUsers(byUsername: username)
.materializeResults()
.map(UserSearchAction.updateUsers)
.throttle(
id: SearchByUsernameID(),
interval: 0.5,
on: environment.mainQueue,
latest: true
)
.observe(on: environment.uiQueue)
...
from reactiveswift-composable-architecture.
Thanks for the explanation @larryonoff 👍 I was thinking about external producers sending multiple values that need to be throttled, not the throttling of Actions back into the reducer.
I'll make Effect.throttle
public in the next release.
from reactiveswift-composable-architecture.
@mluisbrown thanks!
from reactiveswift-composable-architecture.
We should probably make them public in tandem. I'm only reluctant to because while we've defined it, we haven't extensively used or tested it. @larryonoff have you had success with the internal implementation?
from reactiveswift-composable-architecture.
We should probably make them public in tandem. I'm only reluctant to because while we've defined it, we haven't extensively used or tested it. @larryonoff have you had success with the internal implementation?
It works for me. Our QA team soon will start testing it.
from reactiveswift-composable-architecture.
We should probably make them public in tandem.
I agree @stephencelis. I just made the 0.18.0 release and didn't make throttle
public for that reason. Since anyone who needs it can used it by copying the code into their own project for now, it also reduces the urgency.
from reactiveswift-composable-architecture.
FYI in our project using this repo we have started using throttle
and it seems to be working fine, although I haven't verified it exhaustively.
from reactiveswift-composable-architecture.
Effect.throttle
was made public in release 0.22.0 (in #48)
from reactiveswift-composable-architecture.
Related Issues (8)
- Nested properties keyPath support for Produced values HOT 6
- ViewStore version without Combine/SwiftUI HOT 16
- Change TestStore so that it isn't only compiled when running in DEBUG HOT 4
- Multiple calls to store.ifLet HOT 2
- Is there any plans on releasing this framework to CocoaPods? HOT 10
- Object get deallocated on Signal.Observer HOT 3
- Include TCA Swift Concurrency changes from release 0.39.0 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 reactiveswift-composable-architecture.