Giter VIP home page Giter VIP logo

Comments (5)

mike-thompson-day8 avatar mike-thompson-day8 commented on August 16, 2024

Note: at the cost of a wrapping vector literal, this currently works:

{:fx [(when condition (alert-fx/alert "abc"))]}

Ie. {:fx [nil]} will work.

from re-frame.

bowbahdoe avatar bowbahdoe commented on August 16, 2024

That would make our fx abstraction not composable. Currently we define an "effect" as the whole vector of effects

;; STUFF -> EFFECT
(defn alert [stuff]
  [[::alert stuff]])
  
;; STUFF -> EFFECT
(defn log [stuff]
  [[::log stuff]])

This has the benefit of letting more complex stuff like this just be an "effect", and higher layers don't need to care how much is being done.

;; List<EFFECT> -> EFFECT
(defn in-order [& effects]
  (vec (apply concat effects)))
  
;; STUFF -> EFFECT
(defn something-interesting-happened [stuff]
  (in-order (alert stuff) (log stuff)))
    
;; (something-interesting-happened "abc") -> [[::alert "abc] [::log "abc"]]

So there isn't really a clean way to get an {:fx [nil]} without making the functions return just the single tuple.

In what we have, we can do that suggestion inside an in-order call. It just falls apart when we want to return 1 or 0 things to do.

(in-order
  (when condition (alert-fx/alert "abc"))
  (log-fx/log "abc"))

from re-frame.

superstructor avatar superstructor commented on August 16, 2024

I don't think silence on nil is OK esp in the context of this error message being in place for some time. However it needs to be changed to a warning so that users are not misled into thinking that nil is unsupported - if you intended it, then it is fine.

from re-frame.

bowbahdoe avatar bowbahdoe commented on August 16, 2024

...what?

from re-frame.

romdoq avatar romdoq commented on August 16, 2024

@superstructor I don't think this error should have been downgraded to a warning universally, since the intent of the guard against non-sequential values is likely still valid.

If nil should be a supported value for :fx, I think it would be better to cater for nil explicitly where the validity of the argument is checked. Either to :warn only in that specific case (and :error otherwise), or indeed to silently accept nil as a valid value. Eg:

(reg-fx
  :fx
  (fn [seq-of-effects]
    (if-not (or (nil? seq-of-effects)
                (sequential? seq-of-effects))
      (console :error "re-frame: \":fx\" effect expects a seq, but was given " (type seq-of-effects))
      (doseq [[effect-key effect-value] (remove nil? seq-of-effects)]
      ...
(reg-fx
  :fx
  (fn [seq-of-effects]
    (if-not (sequential? seq-of-effects)
      (console (if (nil? seq-of-effects)
                 :warn
                 :error)
               "re-frame: \":fx\" effect expects a seq, but was given " (type seq-of-effects))
      (doseq [[effect-key effect-value] (remove nil? seq-of-effects)]
      ...

My personal preference FWIW would be to silently accept nil as a valid value, since that would be consistent with the behaviour of most Clojure fns which operate on sequences (eg. (concat nil nil) -> ()).

from re-frame.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.