Fork me on GitHub
#fulcro
<
2020-04-07
>
timeyyy10:04:34

Is anyone doing https://enzymejs.github.io/enzyme/ type testing for fulcro? I'd like to render a component and check that a load has been triggered for example

fjolne16:04:46

hi! i wonder whether there’s a way to invoke df/load! with not-yet-mounted app. i use app/set-root! before the load, but it seems like the load tx forces re-render and crashes

Jakub Holý (HolyJak)16:04:13

@tony.kay According to https://github.com/fulcrologic/fulcro/blob/develop/src/main/com/fulcrologic/fulcro/routing/dynamic_routing.cljc#L794 the body of a defrouter is only executed if current-state is one of #{:initial :pending :failed} but in practice it is also executed if it is nil . I guess the docs either need to be corrected or something somewhere fails to set the state correctly to :initial . (This is in a body of a child router when I have routed to a target of a prent router.)

tony.kay17:04:28

@holyjak it will only get nil if you have not set initial state and initialized the routing system before mounting…but you’re right, it’d be fine to tolerate nil

Jakub Holý (HolyJak)17:04:36

Hm, I think I have done that... Let me look more into it

tony.kay17:04:54

@fjolne.yngling bug. that is supposed to be fine, and renders should be ignored if nothing is mounted. which renderer? stack trace? pls open issue.

mss17:04:46

is there a shorthand method for resetting a component to its initial state?

currentoor17:04:10

i dont think so

mss17:04:17

yeah, seems like the easiest way is to just map over the component’s initial state and call set-value! with each kv

tony.kay17:04:54

well, if your initial state actually includes all keys, then (merge/merge-component this ThisClass (comp/get-initial-state ThisClass {})) should do it (check args…not looking at docs)

tony.kay17:04:22

well, and you’d have to make sure to pass in the ID correctly to get-initial-state

tony.kay17:04:28

if it has a non-constant ident

tony.kay17:04:38

and that does the entire sub-tree, of course

tony.kay17:04:24

Then there’s form-state, which is meant to handle this exact case…it has a reset pristine->entity helper to roll back to that last checkpoint

tony.kay17:04:37

and can be told exactly what to track

mss17:04:27

that all makes sense, thanks for the response. feels a little funky to shoehorn the form state into something like a top-level view that’s navigated away from (my case here), but that is interesting

dhale18:04:55

How difficult would it be in fulcro to push 2MB binary buffers (js/ArrayBuffers) from server to remotes? The dev guide discusses (sections 9.4 -- 9.5) getting binary data with http-remote, but I could not find much in the guide or code about pushing binary data with fulcro-websocket.

tony.kay18:04:47

@iradavidhale See RAD file upload code…also beware that websockets are not ideal for pushing large binary data…use two remotes: one for HTTP uploads, and one for your websockets. HTTP is well-designed for pushing binary up

tony.kay18:04:15

(browsers change continuously…I don’t think the websocket spec prohibits it, but I used to hit all sorts of problems trying it)

tony.kay18:04:30

so, short answer: fulcro websockets make no provision for it

tony.kay18:04:37

You could try just sending it in a transit-supported Uint8Array: https://github.com/cognitect/transit-js

tony.kay18:04:29

as in: encoded that was as a mutation parameter (transact! this [(upload {:file buffer})])

tony.kay18:04:53

where upload might get the proper raw bytes in :file parameter on server….have not tried it

tony.kay18:04:20

See js docs for turning your ArrayBuffer into Uint8Array

dhale18:04:49

Thanks! I am a fulcro (and full-stack) beginner, so this is super helpful. I have multiple clients that will all need the same binary data ASAP, which is what made me think of websockets. By "two remotes" I think you are suggesting that (1) the server uses a websocket to tell each client that they need a new buffer, and then (2) they use http to request their buffer. Is that your suggestion?

thosmos23:04:37

that’s how I would do it. I’ve done something like this with server generated EDN endpoints and the clients then did a regular http call to get it. In my case I was able to cache the EDN as a file and use regular file-serving of Nginx to serve it.

dhale19:04:50

Thanks also for the pointer to transit-js bytes. I was looking at transit-cljs and transit-clj (no byte buffers), but should have been looking at transit-js and transit-java. Interop!

tony.kay20:04:14

@iradavidhale So, I’m suggesting that when there is a file to upload you push it via a POST. Fulcro’s file upload support basically can do the lifting for you by encoding both the mutation and the file in one request (see book). With websockets (and http remotes) you can possibly leverage the fact that we’re using transit to just send byte arrays back and forth as parameters…if transit can do it, Fulcro should work with it.

dhale20:04:53

@tony.kay Sorry for the confusion. I think I mis-used "remotes" in my original question. I want to spontaneously (in real time) push big buffers the other way, from http://server.cl to http://clients.cl. This is the key to the app; the other stuff seems easy to do with fulcro.

tony.kay20:04:04

oh, well, just try it…your push received will just get the decoded EDN via transit, so you should just end up with buffers

folcon21:04:37

@tony.kay, sorry about that, I didn’t know to discuss problems here. Re issues with the logic, I’m using the template, I’ve made no login changes whatsoever other than changing the remote to ws-remote

tony.kay21:04:33

is the template still working right with regular rmotes? I’ve not checked it in a very long time…perhaps there was a regression or something…pls try the unmodified template

tony.kay21:04:07

the remote itself should not affect anything if you’ve plugged it in right…should be completely transparent

tony.kay21:04:23

See todomvc example in main Fulcro Repo..I’ve got that set up so I can switch back and forth

folcon21:04:25

I’ve been watching your videos to try and unpick what’s happening. The template does appear to work with the regular remote. I’ll try cloning it from scratch

tony.kay21:04:37

they are not feature-rich, but you can see the clear difference is in middleware

folcon21:04:54

I’ve documented in the issue the specific additions I made as the websockets lib readme uses immutant, not http-kit as the template uses.

folcon21:04:13

Thanks, will read and test =)…

tony.kay21:04:24

I use immutant on a project…works fine. You changed the sente adapter, right?

folcon21:04:57

The websockets themselves appear to work, as I got signup to work

folcon21:04:09

It’s just login that appears to fail

tony.kay21:04:26

weird…that uses a mutation return value

tony.kay21:04:38

wonder if something is wrong in that plumbing

folcon21:04:38

I’m not setting the csrf token, but I figured that wasn’t the issue as signup works…

tony.kay21:04:00

so, for return values to work right, Fulcro has to send a mutation join that includes [*] as the subquery…I think older versions of Fulcro might have missed that?

tony.kay21:04:11

vague memories…

tony.kay21:04:06

The real question is: Did the new session data merge into app state?

tony.kay21:04:22

you could put your broken websocket version on GH and send a link

folcon21:04:44

Sure, 2 secs

currentoor22:04:49

@tony.kay if i recall correctly older versions of fulcro automatically included [*] as a mutation join if you didn’t include a query in the mutation join

folcon22:04:25

Just to be clear, older versions are the non-rad version?

currentoor22:04:40

as they were built before RAD existed yes

currentoor22:04:57

but Im not sure what is the minimum version of fulcro required for rad to work

folcon22:04:47

So is the template version deprecated?

tony.kay22:04:50

@folcon not deprecated…just guessing why you might have issue. template might be defaulting to a version that had a bug? RAD requires latest (SNAPSHOT requires latest SNAPSHOT in some cases)

folcon22:04:51

I’ve forked it with just the websocket changes: https://github.com/folcon/fulcro-template

tony.kay22:04:54

I’m bumping various versions just to start

tony.kay22:04:48

I thought you said immutant?

folcon22:04:25

The readme on fulcro-websockets uses immutant, the default template uses http-kit, I swapped immutant -> http-kit to be in line with the template.

tony.kay22:04:59

It is working fine for me

tony.kay22:04:06

using Fulcro 3.2.0 and latest pathom

tony.kay22:04:27

I signed up with , and then logged in as that user.

tony.kay22:04:37

This template could sure use some love

tony.kay22:04:45

it’s kind of crappy 😜

folcon22:04:11

What deps are you using? (you mentioned you bumped them)

tony.kay22:04:39

diff --git a/deps.edn b/deps.edn
index 9bc7a3a..acace49 100644
--- a/deps.edn
+++ b/deps.edn
@@ -5,8 +5,8 @@
            bk/ring-gzip                        {:mvn/version "0.3.0"}
            com.taoensso/timbre                 {:mvn/version "4.10.0"}
            com.taoensso/tufte                  {:mvn/version "2.1.0"}
-           com.wsscode/pathom                  {:mvn/version "2.2.27"}
-           com.fulcrologic/fulcro              {:mvn/version "3.0.12"}
+           com.wsscode/pathom                  {:mvn/version "2.2.31"}
+           com.fulcrologic/fulcro              {:mvn/version "3.2.0"}
            com.fulcrologic/fulcro-garden-css   {:mvn/version "3.0.7"}
            com.fulcrologic/semantic-ui-wrapper {:mvn/version "1.0.0"}
            com.fulcrologic/guardrails          {:mvn/version "0.0.9"}
@@ -25,7 +25,7 @@
 
  :aliases {:clj-tests {:extra-paths ["src/test"]
                        :main-opts   ["-m" "kaocha.runner"]
-                       :extra-deps  {lambdaisland/kaocha {:mvn/version "0.0-554"}}}
+                       :extra-deps  {lambdaisland/kaocha {:mvn/version "1.0-612"}}}
 
            ;; See  for Emacs support
            :dev       {:extra-paths ["src/test" "src/dev" "src/workspaces"]
@@ -34,7 +34,7 @@
                        :extra-deps  {org.clojure/clojurescript   {:mvn/version "1.10.597"}
                                      thheller/shadow-cljs        {:mvn/version "2.8.80"}
                                      expound                     {:mvn/version "0.8.1"}
-                                     fulcrologic/fulcro-spec     {:mvn/version "3.1.4"}
-                                     binaryage/devtools          {:mvn/version "0.9.11"}
+                                     fulcrologic/fulcro-spec     {:mvn/version "3.1.5"}
+                                     binaryage/devtools          {:mvn/version "1.0.0"}
                                      com.github.awkay/workspaces {:mvn/version "1.0.0-RC2"},
                                      org.clojure/tools.namespace {:mvn/version "1.0.0"}}}}}
~

folcon23:04:00

Btw, this is a fantastic set of tools!

👍 8