Skip to content

Commit

Permalink
Add new FAQ entry on Normalised databases
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-thompson-day8 committed Aug 1, 2017
1 parent 93cfd74 commit e7114d1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
- added [API documentation](/docs/API.md)
- added [testing docs](/docs/Testing.md)
- added [a new mental model](/docs/MentalModelOmnibus.md#on-dsls-and-machines)
- added [a new FAQ entry](docs/FAQs/When-Does-Dispatch-Happen.md) on dispatch processing
- added [a new FAQ entry](/docs/FAQs/When-Does-Dispatch-Happen.md) on dispatch processing
- added [a new FAQ entry](/docs/FAQs/DB_Normalisation.md) on representing normalised data in `app-db`.

#### Breaking

Expand Down
16 changes: 16 additions & 0 deletions docs/FAQs/DB_Normalisation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### Question

`app-db` contains a `map`. How do I store normalised data in a `map`,
bettering mirroring the structure in my server-side database?

### Answer

These libraries might be interesting to you:
- [SubGraph](https://github.com/vimsical/subgraph)
- [pull](https://github.com/juxt/pull)

If you want to go whole hog and ditch `app-db` and embrace DataScript,
then you'll find [re-posh](https://github.com/denistakeda/re-posh) interesting.



3 changes: 2 additions & 1 deletion docs/FAQs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
2. [How can I use a subscription in an Event Handler](UseASubscriptionInAnEventHandler.md)
2. [How do I use logging method X](Logging.md)
3. [Dispatched Events Are Null](Null-Dispatched-Events.md)
4. [Why implement re-frame in `.cljc` files](Why-CLJC.md)
4. [Why is re-frame implemented in `.cljc` files](Why-CLJC.md)
5. [Why do we need to clear the subscription cache when reloading with Figwheel?](Why-Clear-Sub-Cache.md)
6. [How can I detect exceptions in Event Handlers?](CatchingEventExceptions.md)
7. [How do I store normalised data in app-db?](DB_Normalisation.md)



Expand Down
12 changes: 6 additions & 6 deletions docs/FAQs/UseASubscriptionInAnEventHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ because that `subscribe`:

### The Better Way

Instead, the value of a subscription should
Instead, the value of a subscription should
be injected into the `coeffects` of that handler via an interceptor.

A sketch:
```clj
(re-frame.core/reg-event-fx ;; handler must access coeffects, so use -fx
(re-frame.core/reg-event-fx ;; handler must access coeffects, so use -fx
:event-id
(inject-sub [:query-id :param]) ;; <-- will inject subscription value into coeffects
(fn [coeffect event]
(let [sub-val (:something coeffect)] ;; obtain subscription value
(inject-sub [:query-id :param]) ;; <-- interceptor will inject subscription value into coeffects
(fn [coeffects event]
(let [sub-val (:something coeffects)] ;; obtain subscription value
....)))
```

Notes:
1. `inject-sub` is an interceptor which will get the subscription value and add it to coeffects (somehow)
2. The event handler obtains the value from coeffects

So how to write this interceptor?
So, how to write this `inject-sub` interceptor?

### Solutions

Expand Down
2 changes: 1 addition & 1 deletion docs/FAQs/When-Does-Dispatch-Happen.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ How long after I call `dispatch` will the event be processed?
### Answer

The answer is "it depends", but [this comment in the code](https://github.com/Day8/re-frame/blob/master/src/re_frame/router.cljc#L8-L60)
might give you the answers you want.
might provide you the answers you seek.


Up: [FAQ Index](README.md)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Expand Down

0 comments on commit e7114d1

Please sign in to comment.