Giter VIP home page Giter VIP logo

Comments (12)

stephencelis avatar stephencelis commented on May 3, 2024 2

Think this can be closed now :)

from reactiveswift-composable-architecture.

stephencelis avatar stephencelis commented on May 3, 2024 1

@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.

mluisbrown avatar mluisbrown commented on May 3, 2024

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.

mluisbrown avatar mluisbrown commented on May 3, 2024

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.

larryonoff avatar larryonoff commented on May 3, 2024

@mluisbrown

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.

mluisbrown avatar mluisbrown commented on May 3, 2024

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.

larryonoff avatar larryonoff commented on May 3, 2024

@mluisbrown thanks!

from reactiveswift-composable-architecture.

stephencelis avatar stephencelis commented on May 3, 2024

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.

larryonoff avatar larryonoff commented on May 3, 2024

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.

mluisbrown avatar mluisbrown commented on May 3, 2024

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.

mluisbrown avatar mluisbrown commented on May 3, 2024

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.

mluisbrown avatar mluisbrown commented on May 3, 2024

Effect.throttle was made public in release 0.22.0 (in #48)

from reactiveswift-composable-architecture.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.