You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The API is probably stable. Let me know if the API should change, otherwise this API will get bumped to 1.0.0.
8
+
9
+
```swift
10
+
// values
11
+
asyncObservable.value
12
+
asyncObservable.valueStream
13
+
asyncObservable.valueObservable
14
+
15
+
// updates
16
+
asyncObservable.update(2)
17
+
asyncObservable.update { $0+1 }
18
+
asyncObservable.mutate { $0.append(4) }
19
+
```
20
+
3
21
Some of the features that Combine used to offer, but using Swift concurrency and @Observable instead. So it's more compatible with modern setups and should work just fine on any platform.
4
22
Designed for Swift 6.
5
23
6
-
7
24
A single property that is thread safe and can be observed using async streams or @Observable.
8
25
9
26
```swift
@@ -33,10 +50,9 @@ struct SomethingView: View {
33
50
}
34
51
```
35
52
36
-
37
53
## Stream
38
54
39
-
The streams buffering policy defaults to `.unbounded`, so it will "gather" values as soon as you create it.
55
+
The streams buffering policy defaults to `.unbounded`, so it will "gather" values as soon as you create it.
40
56
41
57
```swift
42
58
let someProperty =AsyncObservable(1)
@@ -79,7 +95,7 @@ let stream = someProperty.valueStream // already has 1
79
95
// only print first value
80
96
forawait value in stream {
81
97
print(value) // 1
82
-
break
98
+
break
83
99
}
84
100
85
101
// don't do this ❌
@@ -89,7 +105,7 @@ for await value in stream {
89
105
90
106
// do this ✅
91
107
forawait value in someProperty.valueStream {
92
-
108
+
93
109
}
94
110
```
95
111
@@ -103,8 +119,7 @@ let values = AsyncObservable([1, 2, 3])
103
119
values.mutate { $0.append(4) }
104
120
```
105
121
106
-
107
-
## Buffering Policy
122
+
## Buffering Policy
108
123
109
124
The buffering policy defaults to `.unbounded`, but you can change it on init.
110
125
@@ -127,4 +142,3 @@ Use the `AsyncObservableUserDefaults` class to store values in UserDefaults. Wor
127
142
```swift
128
143
let someProperty =AsyncObservableUserDefaults("someKey", initialValue: "Hello, world!")
0 commit comments