                :data ["my third tweet" 3000]
                :readers #{}
                :writers #{"alice"}}] 1)
-      (let [tweets-in-order (for [result (my-sorted-tweets host6 "alice")]
+      (let [host {:sub (fn [key f])}
+            tweets-in-order (for [result (my-sorted-tweets host "alice")]
                               (:tweet result))]
         (is (= tweets-in-order ["my third tweet"
                                 "my second tweet"

We define such filtering using an optional `:when` key in `defview`."
(fact defview-filt
      (defonce my-atom5 (atom nil))
      (defonce ps5 (ax/pubsub :name))
      (defonce host5 {:sub (:sub ps5)
                      :pub (constantly nil)})
      (defview hashtags-only [user]
        [:tweetlog/tweeted user tweet]
        :store-in my-atom5
        :when (re-matches #".*#[a-zA-Z0-9]+.*" tweet))
      (reset! my-atom5 {})
      (is (= (hashtags-only host5 "alice") [])) ;; Initial call to view function
      ((:pub ps5)
       {:kind :fact
        :name "tweetlog/tweeted"
        :key "alice"
        :data ["No hashtags here..."]
        :ts 1000
        :change 1
        :readers #{}
        :writers #{"alice"}})
      ((:pub ps5)
       {:kind :fact
        :name "tweetlog/tweeted"
        :key "alice"
        :data ["This one hash #hashtags..."]
        :ts 2000
        :change 1
        :readers #{}
        :writers #{"alice"}})
      (is (= (count (@my-atom5 ["alice"])) 1)))

[[:section {:title "Sorting"}]]
"The optional keyword argument `:order-by` directs the view function to sort the elements it returns according to the given expression.
The expression can rely on symbols from the fact pattern, and must result in a [comparable expression](https://clojure.org/guides/comparators)."
(fact defview-sort
      (defonce my-atom6 (atom nil))
      (defonce host6 {:sub (fn [key f])})
      (defview my-sorted-tweets [user]
        [:tweetlog/tweeted user tweet timestamp]
        :store-in my-atom6

                                 :data ["world"]
                                 :readers #{}
                                 :writers #{"alice"}}] -1)
      (let [host {:sub (:sub ps2)
                  :pub #(swap! published2 conj %)
                  :time (constantly 12345)
                  :identity (atom "alice")}]
        (is (= (count (my-tweets2 host "alice")) 0))))

[[:section {:title "Event-Emitting Functions"}]]
"A view provides functions that allow users to emit event for creating, updating and deleting facts."
