Better code in Interceptors docs. Plus fix up titles.

This commit is contained in:
Mike Thompson 2016-08-31 23:27:07 +10:00
parent 5c0268411b
commit 9a9ec3827b
1 changed files with 4 additions and 8 deletions

View File

@ -17,7 +17,7 @@ This is an interceptors tutorial.
* [Self Modifying](#self-modifying) * [Self Modifying](#self-modifying)
* [Credit](#credit) * [Credit](#credit)
* [Write An Interceptor](#write-an-interceptor) * [Write An Interceptor](#write-an-interceptor)
+ [Wrapping Handlers](#wrapping-handlers) * [Wrapping Handlers](#wrapping-handlers)
- [Summary](#summary) - [Summary](#summary)
- [Appendix](#appendix) - [Appendix](#appendix)
* [The Builtin Interceptors](#the-builtin-interceptors) * [The Builtin Interceptors](#the-builtin-interceptors)
@ -260,12 +260,8 @@ And, here it is:
(re-frame.core/->interceptor (re-frame.core/->interceptor
:id :trim-event :id :trim-event
:before (fn [context] :before (fn [context]
(let [new-event (-> context (let [trim-fn (fn [event] (-> event rest vec))]
:coeffects (update-in context [:coeffects :event] trim-fn)))))
:event ;; extra event from coeffects
rest ;; remove first element
vec) ;; list->vector
(assoc-in context [:coeffects :event] new-event)))))
``` ```
As you read this, look back to what a `context` looks like. As you read this, look back to what a `context` looks like.
@ -278,7 +274,7 @@ Notes:
with the backwards processing flow of `:effects`. It is concerned only with the backwards processing flow of `:effects`. It is concerned only
with `:coeffects` in the forward flow. with `:coeffects` in the forward flow.
#### Wrapping Handlers ### Wrapping Handlers
We're going well. Let's do an advanced wrapping. We're going well. Let's do an advanced wrapping.