day8 / re-frame

A ClojureScript framework for building user interfaces, leveraging React
http://day8.github.io/re-frame/
MIT License
5.4k stars 715 forks source link

[Enhancement]: Warning on re-registering subs / events (ie name collision detection) improvements #769

Closed sirmspencer closed 1 year ago

sirmspencer commented 1 year ago
  1. It would be great to have the message show for a newly created sub and a hot reload. We work in shadow-cljs and rarely do a full reload during dev. I am not sure if this is possible, since a hot reload could just end up generating warnings for every sub in the file.

2. Setting to make the message a full error. We don't have any use cases for re adding subs, so an error is more apt.

3. A flag to fail during compilation would also be a great safety net. Basically, we would want it to fail in the ci deployment when we run tests, or build the ubar jar. Maybe a function that can check for duplicates, or any other warnings, that I can add to the test suite.

sirmspencer commented 1 year ago

It looks like I can do #2 with set-loggers! For anyone using shadow the key for both is to call set-loggers from a preload in dev.

(ns sphere.utils.dev-preloads
  (:require [re-frame.core :as rf]))

;; re-frame logging
(defn escalate-re-frame-warn [& r]
  (if (= "re-frame: overwriting" (-> r js->clj first))
    (apply js/console.error r)
    (apply js/console.warn r)))

(re-frame.core/set-loggers! {:warn escalate-re-frame-warn})
sirmspencer commented 1 year ago

I was also able to #3 with set-loggers!. For anyone using shadow the key for both is to call set-loggers! from a preload.

(ns sphere.utils.ci-preloads
  (:require [re-frame.core :as rf]))

(defn escalate-re-frame-warn [& r]
  (assert (not (= "re-frame: overwriting" (-> r js->clj first)))
          (apply str r)))

(defn escalate-re-frame-error [& r]
  (assert false
          (apply str r)))

(re-frame.core/set-loggers! {:warn escalate-re-frame-warn
                             :error escalate-re-frame-error})
mike-thompson-day8 commented 1 year ago

Regarding point 1, re-frame will warn about duplicates on the initial loading of code (up to the window "load" event) but after that, no warnings are issued (during hot code reloading). See https://github.com/day8/re-frame/issues/204

sirmspencer commented 1 year ago

Regarding point 1, re-frame will warn about duplicates on the initial loading of code (up to the window "load" event) but after that, no warnings are issued (during hot code reloading). See #204

I had a guess that might be the case