Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0

import PackageDescription

let package = Package(
name: "OneWay",
platforms: [
.iOS(.v13),
.macOS(.v10_15),
.tvOS(.v13),
.iOS(.v16),
.macOS(.v13),
.tvOS(.v16),
.visionOS(.v1),
.watchOS(.v6),
.watchOS(.v9),
],
products: [
.library(
Expand Down Expand Up @@ -53,10 +53,3 @@ let package = Package(
),
]
)

//for target in package.targets {
// target.swiftSettings = target.swiftSettings ?? []
// target.swiftSettings?.append(
// .enableExperimentalFeature("StrictConcurrency")
// )
//}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ To learn how to use **OneWay** in more detail, go through the [documentation](ht

| OneWay | Swift | Xcode | Platforms |
|--------|-------|-------|-------------------------------------------------------------|
| 3.0 | 6.0 | 16.0 | iOS 16.0, macOS 13, tvOS 16.0, visionOS 1.0, watchOS 9.0 |
| 2.0 | 5.9 | 15.0 | iOS 13.0, macOS 10.15, tvOS 13.0, visionOS 1.0, watchOS 6.0 |
| 1.0 | 5.5 | 13.0 | iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0 |

Expand Down
2 changes: 1 addition & 1 deletion Sources/OneWay/AnyEffect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public struct AnyEffect<Element>: Effect where Element: Sendable {
/// - id: The effect's identifier.
/// - seconds: The duration for which the effect should wait before sending an element.
/// - Returns: A new effect that sends elements only after a specified time elapses.
@available(*, deprecated, renamed: "debounce(id:for:clock:)")
public consuming func debounce(
id: some EffectID,
for seconds: Double
Expand Down Expand Up @@ -133,7 +134,6 @@ public struct AnyEffect<Element>: Effect where Element: Sendable {
/// - dueTime: The duration for which the effect should wait before sending an element.
/// - clock: The clock used for measuring time intervals.
/// - Returns: A new effect that sends elements only after a specified time elapses.
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
public consuming func debounce<C: Clock>(
id: some EffectID,
for dueTime: C.Instant.Duration,
Expand Down
1 change: 0 additions & 1 deletion Tests/OneWayTests/EffectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Clocks
import OneWay
import XCTest

@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
final class EffectTests: XCTestCase {
enum Action: Sendable {
case first
Expand Down
76 changes: 6 additions & 70 deletions Tests/OneWayTests/StoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import OneWay
import OneWayTesting
import XCTest

@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
final class StoreTests: XCTestCase {
private var sut: Store<TestReducer>!
private var clock: TestClock<Duration>!
Expand Down Expand Up @@ -159,91 +158,45 @@ final class StoreTests: XCTestCase {
}

func test_debounce() async {
for _ in 0..<5 {
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 100)
await sut.send(.debouncedIncrement)
}
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 550)
for _ in 0..<5 {
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 100)
await sut.send(.debouncedIncrement)
}
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 550)

await sut.expect(\.count, 2)

for _ in 0..<5 {
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 100)
await sut.send(.debouncedIncrement)
}
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 100) // 100ms < 500ms

await sut.expect(\.count, 2, timeout: 0.1)
}

func test_debounceWithClock() async {
for _ in 0..<5 {
await clock.advance(by: .seconds(10))
await sut.send(.debouncedIncrementWithClock)
await sut.send(.debouncedIncrement)
}
await clock.advance(by: .seconds(100))
for _ in 0..<5 {
await clock.advance(by: .seconds(10))
await sut.send(.debouncedIncrementWithClock)
await sut.send(.debouncedIncrement)
}
await clock.advance(by: .seconds(100))

await sut.expect(\.count, 2)

for _ in 0..<5 {
await clock.advance(by: .seconds(10))
await sut.send(.debouncedIncrementWithClock)
await sut.send(.debouncedIncrement)
}
await clock.advance(by: .seconds(10)) // 10s < 100s

await sut.expect(\.count, 2)
}

func test_deboouncedSequence() async {
for _ in 0..<5 {
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 100)
await sut.send(.debouncedSequence)
}
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 550)
for _ in 0..<5 {
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 100)
await sut.send(.debouncedSequence)
}
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 550)

await sut.expect(\.count, 10)

for _ in 0..<5 {
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 100)
await sut.send(.debouncedSequence)
}
try! await Task.sleep(nanoseconds: NSEC_PER_MSEC * 100) // 100ms < 500ms

await sut.expect(\.count, 10, timeout: 0.1)
}

func test_deboouncedSequenceWithClock() async {
for _ in 0..<5 {
await clock.advance(by: .seconds(10))
await sut.send(.debouncedSequenceWithClock)
await sut.send(.debouncedSequence)
}
await clock.advance(by: .seconds(100))
for _ in 0..<5 {
await clock.advance(by: .seconds(10))
await sut.send(.debouncedSequenceWithClock)
await sut.send(.debouncedSequence)
}
await clock.advance(by: .seconds(100))

await sut.expect(\.count, 10)

for _ in 0..<5 {
await clock.advance(by: .seconds(10))
await sut.send(.debouncedSequenceWithClock)
await sut.send(.debouncedSequence)
}
await clock.advance(by: .seconds(10)) // 10s < 100s

Expand All @@ -260,7 +213,6 @@ private struct TestPublisher: @unchecked Sendable {
private let testPublisher = TestPublisher()
#endif

@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
private struct TestReducer: Reducer {
enum Action: Sendable {
case increment
Expand All @@ -271,9 +223,7 @@ private struct TestReducer: Reducer {
case longTimeTask
case cancelLongTimeTask
case debouncedIncrement
case debouncedIncrementWithClock
case debouncedSequence
case debouncedSequenceWithClock
}

struct State: Equatable {
Expand Down Expand Up @@ -332,24 +282,10 @@ private struct TestReducer: Reducer {
return .cancel(EffectID.longTimeTask)

case .debouncedIncrement:
return .just(.increment)
.debounce(id: Debounce.increment, for: 0.5)

case .debouncedIncrementWithClock:
return .just(.increment)
.debounce(id: Debounce.increment, for: .seconds(100), clock: clock)

case .debouncedSequence:
return .sequence { send in
send(.increment)
send(.increment)
send(.increment)
send(.increment)
send(.increment)
}
.debounce(id: Debounce.incrementSequence, for: 0.5)

case .debouncedSequenceWithClock:
return .sequence { send in
send(.increment)
send(.increment)
Expand Down