Skip to content

Instantly share code, notes, and snippets.

@bherrmann7
Created February 27, 2023 03:57
Show Gist options
  • Save bherrmann7/765f4074dfac013527402fa7f4016ee5 to your computer and use it in GitHub Desktop.
Save bherrmann7/765f4074dfac013527402fa7f4016ee5 to your computer and use it in GitHub Desktop.
(ns app.fortune
#?(:cljs (:require-macros app.fortune))
(:require #?(:clj [clojure.java.shell :as sh])
[hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom]
[hyperfiddle.electric-ui4 :as ui]))
#?(:clj (defn fortune [] (:out (sh/sh "fortune"))))
#?(:clj (defonce !x (atom (fortune))) )
(e/def x (e/server (e/watch !x)))
(e/defn Fortune []
(e/client
(dom/h1 (dom/text "Fortune"))
(dom/pre (dom/text (e/server x)))
(dom/br)
(ui/button (e/fn [] (e/server (reset! !x (fortune)))) (dom/text "New Fortune"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment