                                     (not now-after-trigger))]
           (when (or crossed-forward crossed-backward)
             (let [direction (if crossed-forward :forward :backward)]
-              (when callback (callback direction))
-              (.log js/console "Passed" id "going" direction))))))))
+              (.log js/console "Passed" id "going" direction)
+              (when callback (callback direction)))))))))
 
 (defn waypoint-context [child-el]
   (let [state (atom {})

  (let [rect (.getBoundingClientRect node)]
    (+ (.-top rect) (.-pageYOffset js/window))))

(defn waypoint [child-el options]
  (let [id (gensym "waypoint-id")
        reset-trigger-point! (fn [n]
                               (swap! waypoints assoc-in [id :trigger-point] n))]
    (reagent/create-class
     {:display-name "waypoint"
      :component-will-mount
      (fn []
        (swap! waypoints assoc id {:callback (:callback options)}))
      :component-did-mount
      (fn [this]
        (reset-trigger-point! (get-element-top (reagent/dom-node this))))
      :component-will-unmount
      (fn []
        (swap! waypoints dissoc id))
      :component-did-update
      (fn [this]
        (reset-trigger-point! (get-element-top (reagent/dom-node this))))
      :reagent-render
      (fn [child-el]
        child-el)})))

(defn check-waypoints [last-scroll-y]
  (let [new-scroll-y (.-pageYOffset js/window)]
    (doseq [[id {:keys [callback trigger-point]}] @waypoints]
      (when trigger-point
        (let [was-before-trigger (< last-scroll-y trigger-point)

                      (when (not (:ticking @state))
                        (swap! state assoc
                               :ticking true
                               :last-scroll-y (page-offset)))
                      (.fire throttler))]
    (reagent/create-class
     {:display-name "waypoint-context"
      :component-did-mount
      (fn []
        (.addEventListener js/window "scroll" listener-fn))
      :component-will-unmount
      (fn []
        (.removeEventListener js/window "scroll" listener-fn))
      :reagent-render
      (fn [child-el]
        child-el)})))
