This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-25
Channels
- # announcements (66)
- # aws (1)
- # beginners (60)
- # boot (6)
- # calva (80)
- # cider (3)
- # clj-kondo (14)
- # cljdoc (4)
- # cljs-dev (27)
- # clojure (65)
- # clojure-dev (24)
- # clojure-europe (13)
- # clojure-gamedev (3)
- # clojure-italy (3)
- # clojure-nl (21)
- # clojure-uk (35)
- # clojurescript (98)
- # cursive (25)
- # data-science (3)
- # datomic (10)
- # dirac (16)
- # duct (2)
- # events (2)
- # fulcro (39)
- # jobs-discuss (1)
- # malli (2)
- # other-languages (1)
- # pedestal (26)
- # re-frame (61)
- # reagent (1)
- # reitit (7)
- # shadow-cljs (230)
- # specter (1)
- # tools-deps (29)
- # vim (1)
- # yada (4)
With some changes I made to the core.rrb-vector library recently, the ClojureScript compiler gives a warning that looks reasonable to me, but yet the code seems to work anyway. I was curious if I should be worried about this warning, because code that causes the warning to appear could break with the next ClojureScript compiler release, or whether somehow the fact that it seems to work is really normal somehow (and if so, how?). I've boiled it down to a tiny sample Leininge project here: https://github.com/jafingerhut/ouroboros
The README contains sample output from compiling and running the tests of the code, with the warning message, and a brief explanation of the structure of the code, which is only a couple of dozen lines long.
Hi guys, I had a discussion with 1 developer about state for forms during filling it. I am using r/atom
to keep state for forms in Re-frame. I also saw everybody doing it like this. But today I meet somebody who use re-frame DB instead of reagent.core/atom
. What is your way? How are you doing it? And WHY?
I am asking, because I did library for form validation and I didn’t consider using re-frame DB.
I don't really have an answer because I don't use either re-frame or reagent but in general using the DB decouples it from the component itself
exactly, I think when filling the form and user click on other link you don’t want to keep this state
so do you prefer it when you want to keep the state of not finished (submited) form?
complex forms I generally keep in the DB, simple forms with one or two inputs that I'm fine to lose I'm often fine with local state
hmm, how do you deal with abandoned forms then? Keeping in DB? When user come to form see the state from last time?
I can imagine forms without submit button. Like for example github settings. You click something or lost focus and field is submited.
It all depends on the use-case. It's similar to the way you can work with React input components. Sometimes you want a controlled component, sometimes you don't.
so you could hook into the componentWillUnmount
lifecycle and trigger the removal of the form data there
hmm it sounds like a unnecessary complexity vs just use atom
in form component. But maybe I don’t see good use case.
Unrelated question - do I understand it correct that I cannot parametrize the field that I want to set with set!
? I.e. I want onerror
to be a parameter in a form like (set! (.-onerror n))
.
@kwladyka There's also re-com
library. It's not concerned with forms, it's more low level. But it explicitly makes a choice of not allowing uncontolled components. You always have to provide :on-change
and :model
or something like that. This approach sometimes leads to a few boilerplate lines, but I don't think it can lead to a developer not being able to achieve something with such a library.
E.g. you can use re-com
with both re-frame with its subscriptions and events and Reagent with its local/global ratoms.
@thheller Thanks! @kwladyka Yes, it uses reagent internally, and re-frame is also built on top of reagent.
But I don't think that it actually has to use reagent. It could be abstracted away without too much hassle. Well, assuming the target is React.
I want to keep library independent. I have to rethink solution once again. It is design to use atom
or reagent.core/atom
or different kind of atom, but not to use something what is not atom and is not only for state of this form. Probably I have to provide settings to set how to update state.
I am talking about this library https://github.com/kwladyka/form-validator-cljs
So once again thank you for discussion. I have to figure out how to adapt it to use with DB also.
You can make it possible for a user to choose between controlled and uncontrolled forms. I can't see how it can be limiting for users, but it definitely puts some burden on you as the library's author and maintainer. DB in re-frame is nothing special. Components never work with it directly - they just accept atoms or values (received from re-frame subscriptions) and call some callbacks (that generally should dispatch a re-frame event).
yes, but my initial idea was to keep form in separated state unless submit. Now this idea changed to let user keep it separate or add to 1 global state of the app.
Explained here: https://reactjs.org/docs/forms.html
tl;dr: uncontrolled components can manage their own internal state. They can be asked their current value and they can emit an event when a value is changed by something. Controlled components don't manage any internal state that's not crucial for their work (e.g. you don't want to expose a progress indicator of a component that talks to some backend - it has its state, but it's an implementation detail), so they must receive a value and can receive a change handler.
I have this in deps.edn:
:prod {:extra-paths ["src-cljs-prod"]
:main-opts ["-m" "cljs.main" "-co" "cljs.edn prod.cljs.edn"
"-O" "advanced"
"-d" "out" "-c" ""]}
When I compile I get this:
$ clj -A:prod
Compile sources, elapsed time: 244.941075 msecs
Compile sources, elapsed time: 21.391 msecs
Execution error (BindException) at java.net.PlainSocketImpl/socketBind (PlainSocketImpl.java:-2).
Why does it try to bind to a port?replacing -co with "cljs.edn:prod.cljs.edn"
does what I want, but the behavior is a bit strange
it might try to start a REPL or something? this is the only thing I'm seeing as the output
this is getting interpreted by bash I guess so it'll end up calling cljs.main -co cljs.edn prod.cljs.edn
is the Code Splitting feature appropriate for the purposes of writing a multi .html+.js
browser extension?
do you happen to have any pointers? especially anything specific to writing browser-extensions?
shadow-cljs has some support for writing chrome extensions but it isn't documented anywhere besides the issue itself https://github.com/thheller/shadow-cljs/issues/279
fulcro-inspect uses it, maybe that helps https://github.com/fulcrologic/fulcro-inspect/blob/master/shadow-cljs.edn#L18-L21
I think I want to stick with figwheel-main for now... but so all-in-all, code splitting is appropriate, as long as I handle the context specifics which you mention?
I honestly can't remember most of the details. Haven't done anything browser extension related in over a year
@thheller btw, I appreciate the quick responses and helpfulness from your side!
heya, what's the recommended way of applying js tagged template literals? Is it to instead call the function directly?
I've never actually worked with the template literals, but tagged template literals seem... strange, to say the least. I would definitely just call a function.
they enable some interesting things
some js libraries, like https://emotion.sh/docs/introduction, leverage them
so in that sense the interop is relevant, because if you want to use the library you have to be able to use tagged template literals
Hmm, I see, thanks. Maybe, to support a similar calling convention, it makes sense to create a macro for that.
using re-frame
, I have registered an fx using re-frame/reg-fx
where I make an http call.
How can I set the response to the db
?
https://github.com/day8/re-frame-http-fx/blob/master/src/day8/re_frame/http_fx.cljs#L42 check out how the reframe http-fx lib works. the success/failure handlers are reframe events passed in that are dispatched with the resultant responses
A relevant project: https://github.com/ingesolvoll/re-chain
actually im not using http
directly, but some other effect. should i dispatch an event when it finished to update the db?
How to export prototype properties, eg
(ns a.b)
(defn ^:export mkfoo []
(reify Object
(foo [this])))
;; call in js
;; f = a.b.mkfoo();
;; f.foo() not working
I mean, I dunno, I don't really write any clojurescript, but I think that is the correct thing to do given what I understand about :export and the google closure compiler
and assuming that reify is valid, as I said I don't write clojurescript, and that wouldn't be valid in clojure
When one runs a Node-based ClojureScript REPL using a command like this: clojure -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.520"}}}' -m cljs.main --repl-env node
, what cljs compiler options are used? If there are warning messages from cljs compilation, are they sent to the bit bucket somehow?
I have a project where if I use lein cljsbuld ...
to run tests, I see compilation warnings, but when I run tests using a command like the above, plus -e (clojure.test/run-tests 'my.test.namespace)
at the end, there are no warnings. I was hoping to be able to see them using the clojure
command method, too.
(defrecord NodeEnv [host port path socket proc state]
repl/IReplEnvOptions
(-repl-options [this]
{:output-dir ".cljs_node_repl"
:target :nodejs})
in cljs.repl.node
It might. I have in some cases seen a .cljs_node_repl
directory created, but not always, and I don't know yet what the difference is in the situations where it does create it, vs. not.
I can run a node-based cljs repl given my command above, and evaluate expressions in it, and no such directory is created. Weird.
has anyone been able to get weasel (https://github.com/nrepl/weasel) working with the latest cljs?