Skip to content

Commit

Permalink
Fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftedMind committed Sep 18, 2023
1 parent c3760f1 commit ed80df1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Sources/Processed/Process/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ import SwiftUI
///
/// ```swift
/// @Process var saving
///
/// /* ... */
///
/// $saving.run {
/// try await save()
/// }
Expand All @@ -103,12 +101,14 @@ import SwiftUI
/// }
///
/// @Process<ProcessKind> var action
///
/// /* ... */
///
/// $saving.run(.saving) {
/// $action.run(.saving) {
/// try await save()
/// }
/// $action.run(.deleting) {
/// try await delete()
/// }
/// ```
@MainActor public var projectedValue: Binding {
.init(state: $state, task: $task)
}
Expand Down Expand Up @@ -159,9 +159,7 @@ extension Process {
///
/// ```swift
/// @Process var saving
///
/// /* ... */
///
/// $saving.run {
/// try await save()
/// }
Expand All @@ -176,12 +174,14 @@ extension Process {
/// }
///
/// @Process<ProcessKind> var action
///
/// /* ... */
///
/// $saving.run(.saving) {
/// $action.run(.saving) {
/// try await save()
/// }
/// $action.run(.deleting) {
/// try await delete()
/// }
/// ```
public var projectedValue: Binding {
self
}
Expand Down
47 changes: 47 additions & 0 deletions Sources/Processed/Process/ProcessSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,53 @@

import SwiftUI

/// A protocol that adds support for automatic state and `Task` management for ``Processed/ProcessState`` to the class.
///
/// The provided method takes care of creating a `Task` to run the process in, cancel any previous `Task` instances and setting
/// the appropriate loading states on the ``Processed/ProcessState`` that you specify.
///
/// To start a process, call one of the `run` methods on self with a key path to a ``Processed/ProcessState``
/// property.
///
/// ```swift
/// @MainActor final class ViewModel: ObservableObject, ProcessSupport {
/// @Published var numbers: ProcessState = .idle
///
/// func save() {
/// run {
/// return try await save()
/// }
/// }
/// }
/// ```
///
/// You can run different processes on the same state by providing a process identifier:
///
/// ```swift
/// @MainActor final class ViewModel: ObservableObject, ProcessSupport {
/// enum ProcessKind: Equatable {
/// case saving
/// case deleting
/// }
///
/// @Published var action: ProcessState<ProcessKind> = .idle
///
/// func save() {
/// run(\.action, as: .saving) {
/// return try await save()
/// }
/// }
///
/// func delete() {
/// run(\.action, as: .delete) {
/// return try await delete()
/// }
/// }
/// }
/// ```
///
/// - Note: This is only meant to be used in classes.
/// If you want to do this inside a SwiftUI view, please refer to the ``Processed/Process`` property wrapper.
public protocol ProcessSupport: AnyObject {

/// Cancels the task of an ongoing process.
Expand Down

0 comments on commit ed80df1

Please sign in to comment.