Skip to content

Commit

Permalink
Update README to reflect latest api changes (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrentMifsud authored Oct 2, 2022
1 parent 4625d50 commit c04bdc3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,22 @@ Task 1 Value: New Value

## Using with SwiftUI

### ObservableObject support

`AsyncValue` can be adapted to work seamlessly with `ObservableObject` with a single line of code:

```swift
class MyObservableObject: ObservableObject {
@AsyncValue var myValue: String = "Test" {
// IMPORTANT: you must use `willSet` as that is what `@Published` uses under the hood
willSet { objectWillChange.send() }
}
@AsyncValue var myValue: String = "Test"
}
```

Any changes to an `AsyncValue` will trigger a view update in the same way `@Published` does.

Thanks to [jlsiewert](https://github.com/jlsiewert) for coming up with the cool trick for making this work automatically.

### .onReceive equivalent for `AsyncSequence`

There is also an `.onRecieve(sequence:perform:)` view modifier that allows you to respond to changes from any AsyncSequence.

```swift
Expand All @@ -143,8 +148,6 @@ struct MyView: View {
}

class MyService: ObservableObject {
@AsyncValue var myValue: String = "Test" {
willSet { objectWillChange.send() }
}
@AsyncValue var myValue: String = "Test"
}
```

0 comments on commit c04bdc3

Please sign in to comment.