This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-27
Channels
- # announcements (1)
- # beginners (71)
- # braveandtrue (4)
- # cider (1)
- # cljs-dev (4)
- # cljsrn (8)
- # clojure (111)
- # clojure-italy (5)
- # clojure-spec (22)
- # clojure-uk (8)
- # clojurescript (80)
- # cryogen (14)
- # cursive (7)
- # data-science (1)
- # datomic (25)
- # dirac (1)
- # figwheel-main (4)
- # fulcro (13)
- # incanter (1)
- # off-topic (6)
- # other-languages (3)
- # pathom (11)
- # portkey (5)
- # re-frame (13)
- # reagent (3)
- # reitit (24)
- # ring-swagger (7)
- # shadow-cljs (63)
- # spacemacs (3)
- # specter (4)
- # tools-deps (9)
How to check during compilation time if should I make atom using: reagent.core/atom
or atom
. I wrote library which make atom
to validate-form, but I would like to have it compatible with the most popular libraries.
So if somebody use reagent I want to make atom using reagent.core/atom
, if not use atom
.
it is one of the option, but I would prefer over it detect if developer use reagent or not and then use right one
anyway as I understand this value can be string / number / boolean so I can’t refer to right atom function
i guess this question is more broadly related to javascript in general, but what is a good strategy for having different types of endpoint configurations in the clojurescript code depending upon which environment it is being deployed in ?
the most obvious solutions i can think of is providing an argumen to the build (thus hardcoding endpoints in the javascript, suboptimal), or to assume the host that serves the js bundle has $some endpoint that provides configuration data (like an /config
endpoint, an additional round-trip, but more flexible)
the last i thought of was "just-in-time" compilation of all clojurescript code and injecting the endpoints dynamically that way, but this is also suboptimal for various reasons
(fwiw, i am totally not a frontend developer, so i'm approaching this from a backender's perspective)
@kwladyka see the sidebar regarding macros in https://clojurescript.org/news/2018-03-28-shared-aot-cache
> In those situations, it is recommended that libraries and tooling employ goog.define instead, perhaps with the help of :closure-defines, as this makes JARs cache-friendly. Oh so it is only one option then. Right?
goog-define
will create a specially-handled var in a namespace of your choosing and you can document the qualified symbol for consumers of your library to use with :closure-defines
You can then write conditional code testing that var’s value which will effectively be done at compile time if the library consumer is using :advanced
, all while being compatible with :aot-cache
I suppose for the Reagent atom case, on one branch of the code you would use interop to construct a Reagent atom
stuff that creates problems for future leverage of :aot-cache
should just not be under consideration
Is there any way how I can return multiple values for a reagent function? In Javascript there is a special element that does not get rendered to the dom, so similar to a div, but not put into the dom. I just cannot find this approach for reagent. Any ideas?
@andrea.crotti in #reagent you can use fragments just like in regular React
the hiccup is :<>
, e.g.:
[:<>
[:div "foo"]
[:div "bar"]]
which is the same as:
<>
<div>foo</div>
<div>bar</div>
</>
in JSXThe syntax is so precise; my react/redux apps they are blown up on I think 10 files, just for a basic app.
BTW you can check this branch https://github.com/kwladyka/form-validator-cljs/tree/doc It shows how to use figwheel-main with material-ui in the best way what I know. But this code is under have development. Not finished yet.
You don’t want to use cljsjs packages. size is too big, no optimisation. Always issue with versions etc.
{:names->value {:email ""
:password ""
:password-repeat ""}
:names->validators {:email [::sc/email]
:password [::sc/password]
:password-repeat [?password-repeat]}}
(-> @form
(pprint)
(with-out-str))
pprint show function as #object. Any way to show map exactly as it is defined? With fn name instead #object.
{:names->value {:email "", :password "", :password-repeat ""},
:names->validators
{:email [:form-validator-demo.spec/email],
:password [:form-validator-demo.spec/password],
:password-repeat
[#object[form_validator_demo$views$_QMARK_password_repeat]]}}
What’s the recommended way for a library to opt-in to accessing private variables without triggering a warning? My understanding is that future versions of CLJS will have a warning for private variable access (which is great!) but I’m not sure how to write code that will work both before and after ana/*private-var-access-nowarn*
is introduced
If I try to always bind ana/*private-var-access-nowarn* true
, then that will produce a warning in older CLJS versions. But if I omit it, then presumably the private var access will trigger warning in upcoming versions of CLJS
@kwladyka the issue is that it is printing a function value, which has never really had a decent way to print how that value was defined. One option is to (set! *print-fn-bodies* true)
to see the JavaScript implementation of the function value
{:names->value {:email "", :password "", :password-repeat ""},
:names->validators
{:email [:form-validator-demo.spec/email],
:password [:form-validator-demo.spec/password],
:password-repeat
[#object[form_validator_demo$views$_QMARK_password_repeat "function form_validator_demo$views$_QMARK_password_repeat(form,name){
var password = cljs.core.get_in.call(null,cljs.core.deref.call(null,form),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"names->value","names->value",-1214004968),new cljs.core.Keyword(null,"password","password",417022471)], null));
var password_repeat = cljs.core.get_in.call(null,cljs.core.deref.call(null,form),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"names->value","names->value",-1214004968),name], null));
if(cljs.core._EQ_.call(null,password,password_repeat)){
return null;
} else {
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"password-repeat","password-repeat",-152826064),new cljs.core.Keyword(null,"password-not-equal","password-not-equal",-394108947)], null);
}
}"]]}}
Now it looks like that 🙂(I’m presuming you are dealing with a function value—perhaps it is actually some other object type.)
@mfikes Hm, I’m afraid I’m not sure how to use that in a binding form. I want to do something like
(binding [ana/*private-var-access-nowarn* true]
;; some private var access
)
do you mean I should wrap ana/*private-var-access-nowarn*
in var
e.g. (var ana/*private-var-access-nowarn*)
?
I just mean, do it like you would in Clojure. So, for example you could do
#'clojure.string/replace-all
gotcha, you’re saying I should just use #'
to access the private function (like in CLJ) instead of trying to mess around binding a (possibly non-existent) dynamic variable like ana/*private-var-access-nowarn*
Well, since you mention that dynamic var, it makes me think I may not be understanding what you are doing, maybe you are in Clojure
To zoom out a little, I want to call a private function in CLJS without issuing a warning, regardless of CLJS version (I understand I’m depending on implementation details, and I’m ok with that)
My first idea was to just call the function directly and wrap the call in (binding [ana/*private-var-access-nowarn* true] ,,,)
, which AIUI, would avoid the warning in new versions of CLJS
but now I’m going to try just using #'
to call the private function, as you suggested. I’ll let you know how it goes.
is it possible to write a macro that instruments something at the start some body given as an argument and unstruments something at the end reliably in clojurescript? there seems to be something going on with instrument/unstrument at macro compilation time
It can probably work, but instrument/unstrument is very static currently due to trying to support advanced compilation
OK. I’m running into unexpected behavior right here: https://github.com/slipset/speculative/blob/master/test/speculative/test_test.cljc#L51 which is using this macro: https://github.com/slipset/speculative/blob/master/src/speculative/test.cljc#L36 it only works reliably in clj