 
 
 ;; ------------------------------------------------------------------------------------
-;;  modal-window-OLD  TODO: TO BE REMOVED
-;; ------------------------------------------------------------------------------------
-
-;; CORE.ASYNC REMOVED
-;; (defn listen [el type]
-;;   (let [out (chan)]
-;;     (events/listen el type (fn [e] (put! out e)))
-;;     out))
-
-(def modal-alert (reagent/atom nil))
-
-
-(defn modal-window-OLD [markup status modal-options progress-percent]
-  "Renders a modal window centered on screen. A dark transparent backdrop sits between this and the underlying
-  main window to prevent UI interactivity and place user focus on the modal window.
-  Parameters:
-  - markup            The message to display in the modal (a string or a hiccup vector or function returning a hiccup vector)
-  - status            [optional] The atom used to indicate the process is running (:running, :finished, :cancelled) and that
-  .                   the modal should be shown. Only required when :cancel-button specified.
-  - modal-options     [optional] A map containing two options:
-  .                    - :spinner       A boolean indicating whether to show a spinner or not
-  .                    - :progress-bar? A boolean indicating whether to show a progress bar or not
-  .                    - :cancel-button A boolean indicating whether to show a cancel button or not
-  - progress-percent  [optional] The integer atom used to hold the percentage through the process we are. Used in rendering the progress bar
-  "
-  (let [spinner?       (:spinner       modal-options)
-        progress-bar?  (:progress-bar  modal-options)
-        cancel-button? (:cancel-button modal-options)
-        ;; cancel-id      (gensym "cancel-") ;; CORE.ASYNC REMOVED
-        ]
-
-    ;; (util/console-log "In show-modal-window")
-    (reagent/create-class
-     {
-      :component-did-mount
-      (fn []
-        ;; CORE.ASYNC REMOVED
-        ;; (when cancel-button?
-        ;;   (let [elem   (util/get-element-by-id cancel-id)
-        ;;         clicks (listen elem "click")]
-        ;;     (util/console-log (str "show-modal-window :component-did-mount - " (.-value elem)))
-        ;;     (go (while true
-        ;;           (<! clicks)
-        ;;           (util/console-log "CANCEL CLICKED")
-        ;;           (reset! status :cancelled false)
-        ;;           ))))
-        )
-
-      :render
-      (fn []
-        ;; (util/console-log "show-modal-window :render")
-        [:div
-         {:style {:display "flex"      ;; Semi-transparent backdrop
-                  :position "fixed"
-                  :left "0px"
-                  :top "0px"
-                  :width "100%"
-                  :height "100%"
-                  :background-color "rgba(0,0,0,0.85)"
-                  :z-index 1020
-                  :on-click #(util/console-log "clicked backdrop") ;; Gobble up clicks so they don't go to the main window (TODO: Doesn't work)
-                  }}
-         [:div                         ;; Modal window containing div
-          {:style {:margin "auto"
-                   :background-color "white"
-                   :padding "16px"
-                   :border-radius "6px"
-                   :z-index 1020}}
-          markup
-          (when spinner?       [spinner])
-          (when progress-bar?  [progress-bar progress-percent])
-          (when cancel-button? [cancel-button #(reset! status :cancelled)])
-          #_(when @modal-alert   [:div {:style {:margin "12px"}}
-                                [closeable-alert
-                                 @modal-alert
-                                 (fn [id] (reset! modal-alert nil))]])
-          ]]
-        )
-      })))
-
-
-;; ------------------------------------------------------------------------------------
 ;;  modal-window
 ;; ------------------------------------------------------------------------------------
 

  .                to be used for the subsequent function call and so on.
  - running?       A reagent boolean atom indicating if the processing is running
  "
  (let [schedule (fn reschedule [state]
                   (js/setTimeout
                    #(let [next-state (apply (func) state)]
                       (util/console-log (str "IN reschedule: " state))
                       (when-not next-state (reset! running? false))
                       (when @running? (reschedule next-state)))
                    20))] ;; 20ms should give enough time for UI events to be processed
    (reset! running? true)
    (schedule initial-state)))


;; ------------------------------------------------------------------------------------
;;  looper
;; ------------------------------------------------------------------------------------

(defn looper
  [& {:keys [initial-value func when-done]}]
  (go (loop [pause (<! (timeout 20))
             val   initial-value]
        (let [[continue? out]  (func val)]

            (recur (<! (timeout 20)) out)
            (when-done out))))))



;; ------------------------------------------------------------------------------------
