Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepistrol committed Sep 17, 2023
1 parent dc94547 commit 714fd78
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions Sources/TaskTrigger/TaskTrigger.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import SwiftUI

public struct TaskTrigger<T: Equatable>: Equatable {
public struct TaskTrigger<Value: Equatable>: Equatable {

internal enum TaskState<S: Equatable>: Equatable {
internal enum TaskState<T: Equatable>: Equatable {
case none
case active(value: S, uuid: UUID? = nil)
case active(value: T, uuid: UUID? = nil)
}

/// Creates a new ``TaskTrigger/TaskTrigger``.
public init() {}

internal var state: TaskState<T> = .none
internal var state: TaskState<Value> = .none

/// Triggers the tasks associated with this ``TaskTrigger/TaskTrigger`` and passes along a value of type `T`.
/// Triggers the tasks associated with this ``TaskTrigger/TaskTrigger`` and passes along a value of type `Value`.
/// - Parameters:
/// - value: The value to pass along.
/// - id: (Optional) An UUID which by default is initialized each time this method gets called.
/// In a case a task should not be re-triggered, explicitly pass the same UUID.
mutating public func trigger(value: T, id: UUID? = .init()) {
mutating public func trigger(value: Value, id: UUID? = .init()) {
self.state = .active(value: value, uuid: id)
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/TaskTrigger/TaskTriggerViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

import SwiftUI

struct TaskTriggerViewModifier<T: Equatable>: ViewModifier {
struct TaskTriggerViewModifier<Value: Equatable>: ViewModifier {

typealias Action = @Sendable (_ value: T) async -> Void
typealias Action = @Sendable (_ value: Value) async -> Void

internal init(
trigger: Binding<TaskTrigger<T>>,
trigger: Binding<TaskTrigger<Value>>,
action: @escaping Action
) {
self._trigger = trigger
self.action = action
}

@Binding
private var trigger: TaskTrigger<T>
private var trigger: TaskTrigger<Value>

private let action: Action

Expand Down
8 changes: 4 additions & 4 deletions Sources/TaskTrigger/View+Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public extension View {
/// - trigger: A binding to a ``TaskTrigger/TaskTrigger``.
/// - action: An async action to perform whenever the trigger fires. The attached value
/// is passed into the closure as an argument.
func task<T>(
_ trigger: Binding<TaskTrigger<T>>,
_ action: @escaping @Sendable @MainActor (_ value: T) async -> Void
) -> some View where T: Equatable {
func task<Value: Equatable>(
_ trigger: Binding<TaskTrigger<Value>>,
_ action: @escaping @Sendable @MainActor (_ value: Value) async -> Void
) -> some View {
modifier(TaskTriggerViewModifier(trigger: trigger, action: action))
}

Expand Down

0 comments on commit 714fd78

Please sign in to comment.