Comments (5)
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.
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.
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.
...what?
from re-frame.
@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)
- [Enhancement]: Warn on `subscribe` being used outside of a reactive context HOT 3
- [Enhancement]: Allow enrich to return `nil` HOT 7
- [Enhancement]: Allow subscribe to be safely called from anywhere
- [Enhancement]: Add the UseASubscriptionInAJsEvent page to the FAQs menu in the docs HOT 1
- [Bug]: de-referencing re-frame.db/app-db inside subscription counts as changing data? HOT 1
- [Bug] [Docs]: Simple app example docs out of sync with code in repo
- [Bug]: CSS link path changing with URL HOT 1
- [Enhancement]: Adding syntax sugar :<= for input subscriptions taking the same query vectors. HOT 2
- [Bug]: fix examples projects lockfiles warning HOT 2
- [Enhancement]: Warning on re-registering subs / events (ie name collision detection) improvements HOT 4
- [Enhancement]: reg-event-fx :fx shorthand HOT 3
- [Bug]: Multiple usage of the same standard interceptor creator in global doesn't work HOT 2
- [Enhancement]: Subscriptions that return `nil` or `false` are evaluated regardless of what's in cache HOT 3
- Wenn ich etwas vom Planeten entferne oder davon etwas abbauen, muss ich auch etwas wieder zurückführen damit es im Gleichgewicht bleibt! HOT 1
- [Bug]: Reframe 10x is not being opened with ctrl+h after 1.6.0 HOT 1
- [Enhancement]: Upgrade React dependency to React 18 HOT 3
- Steigende Preise: Die einzige Lösung hier erklärt... HOT 1
- [Bug]: Bump Reagent version up possible?
- Calling `subscribe` in a render fn clashes with reagent optimizations HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from re-frame.