This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-05
Channels
- # babashka (4)
- # bangalore-clj (1)
- # calva (5)
- # chlorine-clover (1)
- # cider (5)
- # clara (9)
- # clj-kondo (18)
- # cljs-dev (12)
- # clojure (42)
- # clojure-europe (9)
- # clojure-norway (1)
- # clojure-uk (4)
- # clojured (255)
- # clojurescript (76)
- # community-development (3)
- # conjure (4)
- # emacs (9)
- # figwheel (3)
- # fulcro (6)
- # graalvm (6)
- # java (15)
- # lsp (7)
- # luminus (1)
- # off-topic (5)
- # pathom (9)
- # reagent (5)
- # ring (6)
- # shadow-cljs (38)
- # sql (21)
- # xtdb (12)
Hi everyone! Newbie here, I want to use clara with clojure/script in the browser, but I'm having a hard time making it work with figwheel and reagent. I was expecting the following code to run println in the rules, but it doesn't seem to work
(ns ^:figwheel-hooks fallas1.nurse
(:require [goog.dom :as gdom]
[reagent.core :as reagent :refer [atom]]
[reagent.dom :as rdom]
[clara.rules
:refer [insert fire-rules]
:refer-macros [defsession defrule]]))
(defsession session 'clara.example)
(defrecord SupportRequest [client level])
(defrecord ClientRepresentative [name client])
(defrule is-important
"Find important support requests."
[SupportRequest (= :high level)]
=>
(println "High support requested!"))
(defrule notify-client-rep
"Find the client representative and request support."
[SupportRequest (= ?client client)]
[ClientRepresentative (= ?client client) (= ?name name)]
=>
(println "Notify" ?name "that"
?client "has a new support request!"))
(defonce app-state
(atom {:session (-> session
(insert (->ClientRepresentative "Alice" "Acme")
(->SupportRequest "Acme" :high))
(fire-rules))}))
(defn main []
[:div
[:h1 (str (:session @app-state))]])
(defn mount [el]
(rdom/render [main] el))
(defn get-app-element []
(gdom/getElement "app"))
(defn mount-app-element []
(when-let [el (get-app-element)]
(mount el)))
(mount-app-element)
(defn ^:after-load on-reload []
(mount-app-element))
@paulocuneo it’s not clear you have println hooked up to js console. So to eliminate that variable try it with js/console.log instead of println first.
But it is also happening during the defonce init so may also be an odd time to see the output. I still think you should be able to get it to print in the js console though
@mikerod Thank you very much! 🙏 I changed it a bit, based on your advise and got it to work.
(ns ^:figwheel-hooks fallas1.nurse
(:require [goog.dom :as gdom]
[reagent.core :as reagent :refer [atom]]
[reagent.dom :as rdom]
[clara.rules
:refer [insert fire-rules]
:refer-macros [defsession defrule]]))
(defrecord SupportRequest [client level])
(defrecord ClientRepresentative [name client])
(defrule is-important
"Find important support requests."
[SupportRequest (= :high level)]
=>
(js/console.log "High support requested!"))
(defrule notify-client-rep
"Find the client representative and request support."
[SupportRequest (= ?client client)]
[ClientRepresentative (= ?client client) (= ?name name)]
=>
(js/console.log "Notify" ?name "that"
?client "has a new support request!"))
(defsession session 'fallas1.nurse)
(defonce app-state
(atom 0))
(defn run-rules [_]
(-> session
(insert (->ClientRepresentative "Alice" "Acme")
(->SupportRequest "Acme" :high))
(fire-rules))
(swap! app-state inc))
(defn main []
[:div
[:div "Rounds:" @app-state]
[:button
{:on-click run-rules}
"run"]])
(defn mount [el]
(rdom/render [main] el))
(defn get-app-element []
(gdom/getElement "app"))
(defn mount-app-element []
(when-let [el (get-app-element)]
(mount el)))
(mount-app-element)
(defn ^:after-load on-reload []
(mount-app-element))
Yeah above makes more sense to me now in terms of making sure evaluation happens at a normal sort of time