Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftedMind committed Sep 17, 2023
1 parent 6b02873 commit 0100d38
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ If you prefer to keep your state in a view model, or if you would like to use Pr
You simply have to conform your class to the `LoadableSupport` protocol that implements the same `load`, `cancel` and `reset` methods as the `@Loadable` property wrapper, but this time defined on `self`:

```swift
@MainActor final class ViewModel: ObservableObject, ProcessSupport, LoadableSupport {
@MainActor final class ViewModel: ObservableObject, LoadableSupport {
// Define the LoadableState enum as a normal @Published property
@Published var numbers: LoadableState<[Int]> = .absent

Expand Down Expand Up @@ -309,7 +309,7 @@ struct DemoView: View {
}
```

Just as with `@Loadable`, you can cancel an ongoing task, by calling `$importantProcess.cancel()` or throw a `CancelProcess()` error from inside the closure. To fully reset the state, there is also a `$importantProcess.reset()` method you can use.
Just as with `@Loadable`, you can cancel an ongoing task by calling `$saving.cancel()` or throw a `CancelProcess()` error from inside the closure. To fully reset the state, there is also a `$saving.reset()` method you can use.


#### Process Identification
Expand Down Expand Up @@ -363,6 +363,40 @@ struct DemoView: View {
}
```

<details>
<summary>Use ProcessState in Classes</summary>

Just as with `LoadableState`, you can also do all the things from above inside a class.

You simply have to conform your class to the `ProcessSupport` protocol that implements the same `run`, `cancel` and `reset` methods as the `@Process` property wrapper, but this time defined on `self`:

```swift
@MainActor final class ViewModel: ObservableObject, ProcessSupport {

enum ProcessKind {
case save
case delete
}

// Define the Process enum as a normal @Published property
@Published var process: Process<ProcessKind> = .idle

func save() {
// Call the run method from the ProcessSupport protocol
run(\.process, as: .save) {
try await save()
}
}

func delete() {
// Call the run method from the ProcessSupport protocol
run(\.process, as: .delete) {
try await delete()
}
}
}
```
</details>

## Example Apps

Expand Down

0 comments on commit 0100d38

Please sign in to comment.