Skip to content

Instantly share code, notes, and snippets.

@knubie

knubie/time.cljs Secret

Created March 22, 2020 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knubie/a031b3db6ad7afb25d91732b3bc76a4d to your computer and use it in GitHub Desktop.
Save knubie/a031b3db6ad7afb25d91732b3bc76a4d to your computer and use it in GitHub Desktop.
(defonce FREQUENCY-MS (* 1000 10))
(def today (r/atom (time/today)))
(re-frame/reg-sub-raw :time/today
;; See https://github.com/Day8/re-frame/blob/master/docs/SubscriptionFlow.md
;; for information on how to use reg-sub-raw.
(fn [app-db _]
(let [interval (js/setInterval #(reset! today (time/today)) FREQUENCY-MS)]
(ratom/make-reaction
#(deref today)
:on-dispose #(js/clearInterval interval)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment