babashka / sci.configs

A collection of ready to be used SCI configs
https://babashka.org/sci.configs/
Other
20 stars 18 forks source link

reagent.core misses macro "reaction" #29

Closed awb99 closed 11 months ago

awb99 commented 1 year ago

https://github.com/reagent-project/reagent/blob/a14faba55e373000f8f93edfcfce0d1222f7e71a/src/reagent/core.clj#L12

(defmacro reaction "Creates Reaction from the body, returns a derefable containing the result of the body. If the body derefs reactive values (Reagent atoms, track, etc), the body will run again and the value of the Reaction is updated.

New Reaction is created everytime reaction is called, so caller needs to take care that new reaction isn't created e.g. every component render, by using with-let, form-2 or form-3 components or other solutions. Consider using reagent.core/track, for function that caches the derefable value, and can thus be safely used in e.g. render function safely." [& body] `(reagent.ratom/make-reaction (fn [] ~@body)))

awb99 commented 11 months ago

I managed to get the macro reaction to work. This works in a sci interpreted cljs file. But it would be better to add the macro reagent.core/reaction to the sci config of reagent.

(ns demo
  (:require
   [reagent.core :as r]
   [reagent.ratom :refer [make-reaction]]))

(defmacro reaction
  [& body]
  `(reagent.ratom/make-reaction
    (fn [] ~@body)))
borkdude commented 11 months ago

Sorry I missed this one