Docs typos

This commit is contained in:
Mike Thompson 2016-12-28 09:05:25 +11:00
parent 51a2e7f5d8
commit 6ae5d8ec4f

View File

@ -204,11 +204,11 @@ On with the rest of my lies and distortions...
### reg-sub-raw
It provides a low level way to register a subscription handler - so the intent is similar to `reg-sub`.
Provides a low level way to register a subscription handler - so the intent is similar to `reg-sub`.
Use is re-frame standard:
```clj
(reg-sub-raw
(re-frame.core/reg-sub-raw ;; it is part of the API
:query-id ;; later use (subscribe [:query-id])
some-fn) ;; this function provides the reactive stream
```
@ -216,18 +216,18 @@ Use is re-frame standard:
The interesting bit is how `some-fn` is written. Here's an example:
```clj
(defn some-fn
[app-db event] ;; app-db is not a value, it is a reagent/atom
(reaction (get-in @app-db [:some :path))) ;; returns a reaction
[app-db event] ;; app-db is not a value, it is a reagent/atom
(reaction (get-in @app-db [:some :path]))) ;; returns a reaction
```
Notice:
1. `app-db` is the first argument and it is not a value, it is a reagent/atom (different to reg-sub!)
2. it returns a `reaction` which does a computation, not a value (different to reg-sub!)
1. `app-db` is the first argument and it is NOT a value, it is a reagent/atom (different to `reg-sub`!)
2. it returns a `reaction` which does a computation, not a value (different to `reg-sub`!)
3. Within that `reaction` `app-db` is deref-ed (see use of `@`)
As a result of point 3, each time `app-db` changes, the `reaction` will rerun. `app-db` is an input signal to that `reaction`.
Unlike `reg-sub`, there is no 3-arity version of `reg-sub-raw`, so you con't provide an input signals function.
Instead, you just use a `subscribe` within the `reaction` itself. For example:
Unlike `reg-sub`, there is no 3-arity version of `reg-sub-raw`, so there's no way for you to provide an input signals function.
Instead, even simplier, you can use any `subscribe` you want within the `reaction` itself. For example:
```clj
(defn some-fn
[app-db event]
@ -238,13 +238,14 @@ Instead, you just use a `subscribe` within the `reaction` itself. For example:
So now this `reaction` has two input signals: `app-db` and `(subscribe [:get-path-part])`. If either changes,
the `reaction` will rerun.
In some cases, the `reaction` might not even
use `app-db` and use only `subscribe` to provide input signals.
In some cases, the returned `reaction` might not even
use `app-db` and, instead, it might only use `subscribe` to provide input signals. In that case, the
registered subscription would belong to "Level 3" of the signal graph (discussed in earlier tutorials).
Remember to deref any use of `app-db` and `subscribe`. It is a rookie mistake to forget. I do it all the time.
Remember to deref any use of `app-db` and `subscribe`. It is a rookie mistake to forget. I do it regularly.
Instead of returning a `reaction` (a macro) you can use `reagent/make-reaction` (a function) which gives you the additional
ability to attach an `:on-dispose` handler to a reaction, allowing you to do comething when the subscription is no longer needed.
Instead of returning a `reaction` (a macro), you can use `reagent/make-reaction` (a utility function) which gives you the additional
ability to attach an `:on-dispose` handler to the returned reaction, allowing you to do cleanup work when the subscription is no longer needed.
[See an example of using `:on-dispose` here](Subscribing-To-External-Data.md)
***