Skip to content

Conversation

@brianium
Copy link
Owner

It has been really enjoyable adding domain specific effects to datastar.wow apps. The update-nexus function serves the purpose well, but the nexus language (while accurate) feels like an odd detail. I am also noticing some patterns emerge in how I pass dependencies to effects and interceptors. I also have some dev tooling that would benefit from being able to dispatch from the REPL so this PR adds that ability as well.

Breaking Changes

Removed :datastar.wow/update-nexus and replaced it with :datastar.wow/registries. :datastar.wow/update-nexus will now be ignored. Adds dispatch
function for creating a dispatch function for "out of band" dispatches.

Changed

Effect + Nexus extension is now powered by registries. A registry IS a Nexus map, but with :datastar.wow namespaced keys. Keys are aliased
not to aura farm, but to reduce cognitive load (single require is a good thing).

(def effect-map
  {::d*/effects
    {::myeffect
      (fn [ctx system arg1]
        (println arg1))}})

(defn effect-map-fn []
  {::d*/effects
    {::myeffect
      (fn [ctx system arg1]
        (println arg1))}})

(defn effect-map-fn-1
  [arg1]
  {::d*/effects
    {::othereffect
      (fn [ctx system]
        (println arg1))}})

;;; No more ::d*/update-nexus
(d*/with-datastar ->sse-response {::d*/registries [effect-map effect-map-fn [effect-map-fn-1 \"Mama mia!\"]]})

The vector syntax is particularly useful for scenarios using a component system like integrant.

(require '[integrant.core :as ig])

(def config
  {::datastar-config
    {::d*/registries [effect-map effect-fn [sql-effect (ig/ref ::database-fn)]]}})

Added

Adds a dispatch function that takes a subset of with-datstar options: ::d*/registries, ::d*/write-json, and ::d*/write-html. This
dispatch can be passed to with-datastar.

(def my-dispatch (d*/dispatch {::d*/registries [my-app-effects]}))

(d*/with-datastar ->sse-response {::d*/dispatch my-dispatch})

If a dispatch function is given, ::d*/registries, ::d*/write-json, and ::d*/write-html options given to with-datastar will be ignored.

@brianium brianium merged commit b7910c0 into main Sep 20, 2025
6 checks passed
@brianium brianium deleted the refactor/registry branch September 20, 2025 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants