Fork me on GitHub
#fulcro
<
2019-01-18
>
tony.kay07:01:51

General Notice: Fulcro Spec 3.0 is in out…it is a breaking change: I’m removing the browser renderers. I just don’t have the time to maintain them, they are flaky, and there are good alternatives. The shadow-cljs default test renderer is quite good at this point (I just ported Fulcro to it, and it’s fine), and Kaocha or an Emacs/IntelliJ/Vim in-editor runner for clj is better as well. The docs in fulcro-spec, and the example on develop of Fulcro show how to change up a project. Fulcro is getting a bump as well soon. I’m changing over to shadow-cljs for the development there because the experience is just so much better. I’ve pretty much got it going on the develop branch. Not sure what the version number will be yet. It should not look like much of a change externally…

👍 15
tony.kay07:01:06

also converting them to deps.edn, which could cause some dependency weirdness…that is the main noticeable change probably

Teemu Kaukoranta14:01:42

Hi! I'm trying to follow along the fulcrologic book, but I can't get the remote data loading working. I'm at a point where my client is supposed load in the :started-callback, but I don't see anything in Fulcro Inspects Network tab, and when I try to call the callback manually using shadow-cljs's repl (with ((:started-callback @app.client/app))), I get repl/invoke error Error: No protocol method IDeref.-deref defined for type null. I've restarted the server, and refreshed the browser.

Teemu Kaukoranta14:01:32

It seems like there's something wrong with my app initialization.. even when I do

(defonce app (atom (fc/new-fulcro-client
                     :initial-state {:some-data 42})))
, I'm not seeing any initial data in fulcro inspect, and repl says :initial-state of @app is nil

Teemu Kaukoranta14:01:10

Ah, I found the bug. The template the book uses has a new reset! call in the init function. I had to add the :started-callback there instead

tony.kay16:01:10

There’s an error in the book, or an inconsistency with the template? Either way I’d like to know about it 🙂

tony.kay16:01:16

details appreciated

Teemu Kaukoranta21:01:08

The template defs the atom as nil, and in the init fn resets the fulcro app into it

Teemu Kaukoranta21:01:53

In the book you replace the nil value in the atom with a fulcro app

Teemu Kaukoranta18:01:30

Ping @tony.kay, not sure you noticed this

tony.kay18:01:54

Ah, thanks…I did miss it

tony.kay18:01:31

When I said “detail”, I was looking for something that doesn’t require me to find the exact files and lines….something like “In the book where it says “something I can search for with a reasonable chance of accuracy” and in the template in file xxx it does blah on line xxx…The book is 500 pgs 🙂

tony.kay18:01:01

There is a lot of stuff, and my time is limited

tony.kay18:01:36

Even better would be github links to lines. The develop guide is in the root of the fulro repo, and the lein template is OSS as well

Teemu Kaukoranta20:01:29

Ah sorry, I'll try to remember to do that tomorrow 🙂 I understand completely

Teemu Kaukoranta20:01:35

I was on mobile when I wrote that

tony.kay20:01:50

cool, thanks

Teemu Kaukoranta11:01:18

http://book.fulcrologic.com/#_setting_up_a_server under header "Triggering the Load". The example says to change the (defonce app (atom ..)). I think the example should be this

(ns app.client
  (:require [fulcro.client :as fc]
            [fulcro.client.data-fetch :as df]               ; (1)
            [app.ui.root :as root]
            [fulcro.client.network :as net]))

...

(defn ^:export init []
  (reset! app (fc/new-fulcro-client
                ;; This ensures your client can talk to a CSRF-protected server.
                ;; See middleware.clj to see how the token is embedded into the HTML
                :networking {:remote (net/fulcro-http-remote
                                       {:url                "/api"
                                        :request-middleware secured-request-middleware})}
                :started-callback
                (fn [app]  ; (2)
                  (df/load app :current-user root/Person))))
  (start))
I checked that this applies to the updated fulcro template too. @tony.kay

tony.kay16:01:03

Thanks, I’ll take a look!

hmaurer16:01:58

@tony.kay Hi 🙂 Is https://github.com/fulcrologic/fulcro-template what I should be looking at for an up-to-date example of how to set up an application with routing?

tony.kay16:01:32

well, “it depends” @hmaurer

tony.kay16:01:12

The routing in there is the “best supported”.

tony.kay16:01:00

I think the dynamic routing in incubator is going to eventually be the best…and the features are good…the problem is it isn’t battle tested yet. It is known not to work with SSR, for example.

😞 5
hmaurer16:01:58

@tony.kay Ah, well, I have no need for SSR. I just need routing that I can get up to speed with quickly. My use-case is a fairly simple application with a login page, and once logged in a few routes (some of which with route parameters).

tony.kay16:01:19

probably go with template for small apps

hmaurer16:01:00

Would the dynamic routing be more straightforward to implement / play better with Fulcro ?

hmaurer16:01:43

Also, would it make it more straightforward to load data for specifc routes then render the UI, etc?

hmaurer16:01:59

(and show some loading indicator in the process)

tony.kay16:01:02

all of the above

tony.kay16:01:18

see the docs

tony.kay16:01:22

in incubator

tony.kay16:01:44

it has deferred routing

hmaurer16:01:47

looking at it now

hmaurer16:01:34

Docs look good, I’m going to give it a whirl tonight!

hmaurer16:01:19

Additional question: is there a neat way to fit an authentication flow into this? Roughly speaking I would want to put most of the routes behind a requirement that the user is authenticated, and if no (after running a check against the server), redirect to the login route

tony.kay16:01:19

great, love to hear how it goes…have not had much chance to use that yet

tony.kay16:01:09

You’re responsible for calling the route functions…so your logic dictates what is reachable…I’d use UI state machines in incubator

tony.kay16:01:42

one state machine on the top level that controls routing

tony.kay16:01:58

of course using a diff state machine on the login screen is nice too, and the docs show an example of one of those

hmaurer16:01:51

it seems up to date (8th dec) 🙂

tony.kay17:01:29

yep, that’s all recent stuff

tony.kay21:01:02

NOTE: There is a new version of the lein template. It uses deps.edn, shadow’s test renderer, pathom for the back-end, and kaocha for clj tests at CLI.

😍 20
hmaurer02:01:55

Just tried it out tonight; it’s great. A lot of it I had to set up manually on my project (i.e. koacha); it’s nice to see it in a template. And it got me to watch a talk on Pathom

tony.kay18:01:04

good to hear

tony.kay21:01:15

appreciate feedback, esp from @wilkerlucio on the pathom setup