Skip to content

Commit 1ff4887

Browse files
committed
Adjust README
1 parent 22dff4b commit 1ff4887

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class Dog: Observer {
109109

110110
### Observers
111111

112-
Each observation involves one *observer* observing one other object. By conforming to `Observer`, the *observer* adopts functions for starting and ending observations. <a id="combined-observations"></a> You may start up to three observations with one combined call:
112+
By conforming to `Observer`, the *observer* adopts functions for starting and ending observations. Each observation involves one *observer* and one observed object. <a id="combined-observations"></a> An `Observer` may start up to three observations with one combined call:
113113

114114
~~~swift
115115
dog.observe(tv, bowl, doorbell) { image, food, sound in
@@ -141,12 +141,12 @@ For objects to be observable, they must conform to `Observable`. There are four
141141
You use every `Observable` the same way. There are only three things to note:
142142

143143
1. Observing an `Observable` does not have the side effect of keeping it alive. Someone must own it via a strong reference. (Note that you can still [observe with a chain of ad hoc transformations](#ad-hoc-mapping) all in a single line.)
144-
2. The property `latestMessage` typically returns the last sent *message* or one that indicates that nothing changed. It's a way for clients to request (pull) the "current" message or value, in addition to waiting for the `Observable` to send (push) the next. [Combined observations](#combined-observations) also rely on `latestMessage`.
144+
2. The property `latestMessage` typically returns the last sent *message* or one that indicates that nothing changed. It's a way for clients to request (pull) the "current" message, in addition to waiting for the `Observable` to send (push) the next. [Combined observations](#combined-observations) also rely on `latestMessage`.
145145
3. Typically, an `Observable` sends its *messages* by itself. But anyone can make it send `latestMessage` via `send()` or any other *message* via `send(_:)`.
146146

147147
# Memory Management
148148

149-
To avoid abandoned observations piling up in memory, *observers* should, before they die, stop the observations they started. One way to do that is to stop each observation when it's no longer needed:
149+
To avoid abandoned observations piling up in memory, *observers* should, before they die, stop their observations. One way to do that is to stop each observation when it's no longer needed:
150150

151151
```swift
152152
dog.stopObserving(Sky.shared)
@@ -162,7 +162,7 @@ class Dog: Observer {
162162
}
163163
```
164164

165-
The observations in which an *observable* is involved stop automatically when the *observable* dies, so it doesn't need to do anything in `deinit`. But it can always stop all its observations via `observable.stopObservations()`.
165+
You can stop an *observable's* observations via `observable.stopObservations()`. But when an *observable* dies, it automatically stops all its observations, so you don't need to do anything in its `deinit`.
166166

167167
Forgetting some observations wouldn't waste significant memory. But you should understand, control and express the mechanics of your code to a degree that prevents systemic leaks.
168168

@@ -175,7 +175,7 @@ The three above mentioned functions are all you need for safe memory management.
175175
176176
# Variables
177177

178-
A `Var<Value>` has a property `value: Value`. If `Value` conforms to `Equatable` or `Comparable`, the whole `Var<Value>` will also conform to the respective protocol.
178+
A `Var<Value>` has a property `value: Value`. If `Value` is `Equatable` or `Comparable`, the whole `Var<Value>` will also conform to the respective protocol.
179179

180180
## Use Variable Values
181181

@@ -190,11 +190,11 @@ number <- 42 // number.value == 42
190190

191191
### Number Values
192192

193-
If `Value` is either `Int`, `Float` or `Double`:
193+
If you use some number type `Number` that is either an `Int`, `Float` or `Double`:
194194

195-
1. Every `Var<Value>`, `Var<Value?>`, `Var<Value>?` and `Var<Value?>?` has either `var int: Int`, `var float: Float` or `var double: Double`, which is non-optional and interprets `nil` values as zero.
195+
1. Every `Var<Number>`, `Var<Number?>`, `Var<Number>?` and `Var<Number?>?` has either a `var int: Int`, `var float: Float` or `var double: Double`. That property is non-optional and interprets `nil` values as zero.
196196

197-
2. You can apply numeric operators `+`, `-`, `*` and `/` to all pairs of `Value`, `Value?`, `Var<Value>`, `Var<Value?>`, `Var<Value>?` and `Var<Value?>?`.
197+
2. You can apply numeric operators `+`, `-`, `*` and `/` to all pairs of `Number`, `Number?`, `Var<Number>`, `Var<Number?>`, `Var<Number>?` and `Var<Number?>?`.
198198

199199
3. ```swift
200200
let numVar = Var<Int?>() // numVar.value == nil
@@ -205,13 +205,13 @@ If `Value` is either `Int`, `Float` or `Double`:
205205

206206
### String Values
207207

208-
1. Every `Var<String>`, `Var<String?>`, `Var<String>?` and `Var<String?>?` has a `var string: String` which is non-optional and interprets `nil` values as `""`.
208+
1. Every `Var<String>`, `Var<String?>`, `Var<String>?` and `Var<String?>?` has a `var string: String`. That property is non-optional and interprets `nil` values as `""`.
209209
2. Representing its `string` property, every `Var<String>` and `Var<String?>` conforms to `BidirectionalCollection`, `Collection` and `Sequence`.
210210
3. You can apply concatenation operator `+` to all pairs of `String`, `String?`, `Var<String>`, `Var<String?>`, `Var<String>?` and `Var<String?>?`.
211211

212212
## Observe Variables
213213

214-
A `Var<Value>` sends *messages* of type `Change<Value>`, providing the `old` and `new` value:
214+
A `Var<Value>` sends *messages* of type `Change<Value>`, providing the `old` and `new` value, with `latestMessage` holding the current `value` in both properties: `old` and `new`.
215215

216216
~~~swift
217217
observer.observe(variable) { change in
@@ -221,9 +221,7 @@ observer.observe(variable) { change in
221221
}
222222
~~~
223223

224-
A `Var` sends a `Change<Value>` whenever its `value` actually changes. Just starting to observe the `Var` does **not** trigger a *message*. This keeps it simple, predictable and consistent, in particular in combination with [*mappings*](#mappings).
225-
226-
You can always manually send `latestMessage` via `send()`. The `Change<Value>` that `latestMessage` returns on a `Var` holds the current `value` in both properties: `old` and `new`.
224+
A `Var` sends a `Change<Value>` whenever its `value` actually changes. Just starting to observe the `Var` does **not** trigger a *message*. This keeps it simple, predictable and consistent, in particular in combination with [*mappings*](#mappings). Of course, you can always manually send `latestMessage` via `send()`.
227225

228226
Internally, a `Var` appends new values to a queue, so all its *observers* get to process a `value` change before the next change takes effect. This is for situations when the `Var` has multiple *observers* and at least one of them changes the `value` in response to a `value` change.
229227

@@ -282,7 +280,7 @@ As [mentioned earlier](#observables), you use a *mapping* like any other `Observ
282280

283281
## Swap Mapping Sources
284282

285-
You can even reset the `source`, causing the *mapping* to send a *message* (with respect to its [*filter*](#filter)). Although the `source` is replaceable, it's of a specific type that you determine by creating the *mapping*.
283+
You can also reset the `source`, causing the *mapping* to send a *message* (with respect to its [*filter*](#filter)). Although the `source` is replaceable, it's of a specific type that you determine by creating the *mapping*.
286284

287285
So, you may create a *mapping* without knowing what `source` objects it will have over its lifetime. Just use an ad-hoc dummy *source* to create the *mapping* and, later, reset `source` as often as you like:
288286

@@ -567,7 +565,7 @@ If your `Message` is optional, you can also erase the buffered *message* at any
567565

568566
## Make State Observable
569567

570-
To inform *observers* about value changes, similar to `Var<Value>`, you would use `Change<Value>`, and you might want to customize `latestMessage` so it returns the latest value rather than the last sent *message*:
568+
To inform *observers* about value changes, similar to `Var<Value>`, you would use `Change<Value>`, and you might want to customize `latestMessage` so it returns a message based on the latest (current) value:
571569

572570
~~~swift
573571
class Model: CustomObservable {

0 commit comments

Comments
 (0)