This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-26
Channels
- # aws (1)
- # beginners (50)
- # boot (32)
- # chestnut (2)
- # cider (14)
- # clara (23)
- # cljs-dev (131)
- # cljsrn (44)
- # clojure (133)
- # clojure-belgium (3)
- # clojure-denmark (4)
- # clojure-dev (6)
- # clojure-italy (4)
- # clojure-nl (2)
- # clojure-russia (95)
- # clojure-spec (59)
- # clojure-uk (14)
- # clojurescript (157)
- # cursive (26)
- # data-science (1)
- # datomic (160)
- # devops (5)
- # dirac (80)
- # emacs (2)
- # graphql (2)
- # jobs (2)
- # lein-figwheel (1)
- # lumo (9)
- # off-topic (151)
- # onyx (2)
- # parinfer (2)
- # pedestal (5)
- # perun (2)
- # re-frame (60)
- # reagent (3)
- # remote-jobs (1)
- # test-check (3)
- # uncomplicate (11)
- # yada (1)
Is there a way of tearing down async-flow-fx
flows? I'm working on tests (using re-frame-test for the first time) and some of the flows didn't terminate, but with every test run the async flows accumulate
related - using re-frame test is it possible to run async tests that depend on other async tests. e,g, for me app/initialize is async, so is login, and both of those I'd like to reuse in subsequent tests. I'm getting obscure null pointer errors (with no stacktrace because it's react native , š³) but I can't tell if I'm trying to use it for something it's not designed for.
(deftest initialize
(reframe-test/run-test-async
(test-fixtures)
(let [loading-state (reframe/subscribe [:ui.global/loading-state])]
(reframe/dispatch [:app/initialize])
(reframe-test/wait-for [:app.initialize/success]
(println "Initialized")
(is (= @loading-state :ui.loading-states/loaded))))))
(deftest login
(reframe-test/run-test-async
(let [login-state (reframe/subscribe [:ui.login/login-state])]
(initialize) <-- can I do this??? or this kinda thing??
(reframe/dispatch [:ui.login/set-email ""])
(reframe/dispatch [:ui.login/set-password "success"])
(reframe/dispatch [:ui/login])
(reframe-test/wait-for [:ui.login/success :ui.login/failure]
(println "Logged in")
(println @login-state)
(is (= @login-state :ui.login.login-states/logged-in))))))
Does anyone have a link to a write-up of how to use the new(-ish) re-frame cofx stuff for those of us who were brought up on good ol' register-handler
?
@pandeiro The docs on the github repo are pretty decent (if you havenāt seen those yet ā I know I missed them the first time I went through the front-page README stuff)
Hi, Iām looking for ābest practicesā for forms in re-frame. Itās taking a little getting used to, but Iāve gotten my brain around the āglobal immutable stateā, etc I think. So say for a login form, iāll have a {:login-form-data {:name nil :password nil}
entry in the db. So now I have a login form. When Iām say handling the onChange for the name field, should I be doing a dispatch for it (and by extension every) field? Whatās the best approach for subscriptions/handlers in this case? it seems like having one per field would be trivial in this case, but would get tedious very quickly
I canāt speak for best practices, but I have tried both having form state in a local ratom (i.e. inside a let
in the component definition), versus keeping a form in my app db under something like [:ui :forms :login :username]
etc.
Whatās nice about the latter approach is that it makes it very easy to have a single :verify-login-form event that goes through and validates all your inputs, plus a set of subscriptions to the list of validation errors.
Yeah, if youāre using a local ratom you wait until the form submit and then dispatch a login event.
in fact for something as simple as a login, I might be tempted to use the local ratom even if I were using the longer app-db style for more complex forms
so then once thereās data for a given form, youād say copy the data from the app-db to the local ratom for edit, etc?
I should say, for the local ratom login form, Iād create the ratom at the level of a form group, and then have each form field access the ratom, but you get the idea.
Yeah, for real forms, I like the longer, app-db-based approach, on the theory that you can copy/share validation between the form and the current db data, and itās easier to move stuff to/from the edit form
Ok, so basically, have a āform cacheā in a local ratom. I can do enhanced stuff as necessary against some app-db copy. Post validation, do a dispatch that would say update the app-db, call the server (or perhaps the other way around), etc.
Itās worth playing with, but I found it limiting in the long run. Easier in the short term, but you might regret it later (unless itās something really trivial/ephemeral like a login form).
ah wait, sorry I think I misunderstood, youāre saying that was ultimately better to work directly with the app-db?
if so, how did you handle the dispatching, etc. something like an subscription/handler for the whole form?
No, I dispatched each field/button separately, but I used a common dispatch function that took, as arguments, which field to update, plus the value
so something like #(re/dispatch [:login-form/update-field :username (-> % .-target .-value)])
Ok, gotcha, Iāve been hacking away a bit and have kind of arrived at something similar I think
:thumbsup:
Hello all, do you think is there side effects doing this?
(reg-event-db
:clean-login-fields
(fn [db [_]]
(assoc db :username "")
(assoc db :password "")))
so, on the grabbing it back I did more or less what you do for form ratoms (let [formdata @(rf/subscribe [:formdata])) ...
then have my form fieldsā values key into that
@eoliphant That works. On my first iteration I did it more reagent style (let [formdata (reagent.atom/atom {})] ...)
(donāt remember the exact syntax off the top of my head, but thatās the idea)
but that got tedious because everything that does anything to the form data has to live inside the let
validation etc.
much nicer to have it update the app db, so you can share validation fns between forms, etc.
In fact I tend to name my forms things like :address-editor
, so itās living at [:ui :editors :address-editor]
in my app db. Then I can use the same clojure spec for the data when itās being edited, and when it isnāt, and itās easy to move from one to the other.
and if I have an :email
field in multiple different editors, they can all share the same validation fns (and Clojure spec).
Like I say, I canāt speak to ābest practiceā but Iāve been a bit happier with keeping everything in the app db except for really ephemeral stuff
Iāve already pretty much captured their core datamodel in literally a page of code and edn.
just ran into something interesting, iām still figuring all of this out, but I just noticed in my form that iāve converted from the ratom approach to the app db approach grabbing the entire formās data in the let isnāt reactive
(defn test-form
[]
(let [formdata @(rf/subscribe [:test-form])]
(fn []
....
:value (:testfield2 formdata)
Doesnāt work. But the following does:
:value (:testfield1 @(rf/subscribe [:test-form]))