                 (+ prev-scroll-top (- curr-scroll-height prev-scroll-height)))))
       :reagent-render
       (fn [set-current-location locations]
-        [:div.comic-list (map #(make-comic-image set-current-location %) locations)])})))
+        [waypoint-context
+         [:div.comic-list (map #(make-comic-image set-current-location %) locations)]])})))

   (fn [app-db [_ location image-tag]]
     (assoc-in app-db [:images location] image-tag))))

(defn make-waypoint [options]
  (js/Waypoint. (clj->js options)))

(defn make-img-did-mount [set-waypoints! set-current-comic]
  (fn [this]
    (let [node (reagent/dom-node this)
          wp-down (make-waypoint {:element node
                                  :group "comic-image"
                                  :continuous true
                                  :handler #(when (= % "down")
                                              (set-current-comic))})
          wp-up (make-waypoint {:element node
                                :group "comic-image"
                                :continuous true
                                :offset "bottom-in-view"
                                :handler #(when (= % "up")
                                            (set-current-comic))})]
      (set-waypoints! [wp-up wp-down]))))

(defn replace-waypoints [waypoints new-waypoints]
  (doseq [wp waypoints]
    (.destroy wp) )
  new-waypoints)

(defn comic-image [set-current-comic tag]
  (let [waypoints (atom nil)
        set-waypoints! #(swap! waypoints replace-waypoints %)]
    (reagent/create-class
     {:display-name "comic-image"
      :component-did-mount
      (make-img-did-mount
       set-waypoints!
       set-current-comic)
      :component-will-unmount #(set-waypoints! nil)
      :reagent-render
      (fn [_ tag]
        (if (= tag :loading)
          [base/loading]
          [:div.row
           [:div.medium-12.columns tag]]))})))

(defn comic-image-container [set-current-comic location]
  (let [image (re-frame/subscribe [:image location])]

            [reagent.core :as reagent]
            [comic-reader.api :as api]
            [cljsjs.waypoints]
            [comic-reader.ui.base :as base])
  (:import (goog.async Throttle)))

(defn setup! []
  (re-frame/reg-sub
