DevYeom / OneWay

A Swift library for state management with unidirectional data flow.
https://swiftpackageindex.com/DevYeom/OneWay/2.9.0/documentation/oneway
MIT License
78 stars 8 forks source link

Add a debouncing operator #57

Closed DevYeom closed 10 months ago

DevYeom commented 10 months ago

Related Issues 💭

Description 📝

Add a new operator that sends elements only after a specified time interval elapses between events.

Additional Notes 📚

enum Debounce {
    case increment
}
func reduce(state: inout State, action: Action) -> AnyEffect<Action> {
    switch action {
// ...
    case .debounce:
        return .just(.increment)
            .debounce(id: Debounce.increment, for: 0.5)

    case .debounceWithClock:
        return .just(.increment)
            .debounce(id: Debounce.increment, for: .seconds(1), clock: .continuous)
// ...
    }
}

Checklist ✅