Fork me on GitHub
#fulcro
<
2019-08-15
>
jimrthy05:08:34

This feels like it should be a really silly, obvious FAQ. So I apologize if it is. Is there a recent example of using fulcro with a datomic back-end? All my searches turn up results about a) parsing queries into graphql or b) the deprecated fulcro-datomic library (BTW: thank you so much for picking up where Om Next left off!)

pithyless12:08:17

@jimrthy We use Pathom to handle all our backend mutations and queries. This abstracts away whether we're hitting Datomic, HTTP, or some other data store. When handling the request, a middleware adds to the pathom env {:db-ref (atom (d/db datomic-conn))}. Any pathom resolver can access this db to get a consistent read and pull out any data (could be a simple d/pull or something more complicated). We store it as an atom (and not just a value), because if there is a mutation, the mutation will d/transact and reset! the db-ref to the new value. This let's us guarantee read-after-write semantics for a pathom mutation+query. In practice, we separate resolvers that do joins (ala d/q to find entity ids) and resolvers that just fetch attributes (ala d/pull on existing entity ids). All resolvers whitelist attributes returned and check permissions of current-user.

jimrthy04:08:50

Awesome. Thank you!

bbss06:08:35

@jimrthy I am actually using fulcro with datomic but I haven't find many authorative examples/utility libs either, but I didn't search too much so if there is one I'd like to know too. However the fulcro3-template uses datascript (= datomic-ish) in the back-end: https://github.com/fulcrologic/fulcro3-template/blob/master/src/main/app/model/account.clj Note that nowadays fulcro (fulcro3 anyway..) leaves the back-end code to pathom.

cjmurphy06:08:55

@jimrthy You can follow Fulcro/other examples that exist for creating your own web server (so not the 'easy' server). Bear in mind that the defquery-root, defquery-entity and defmutation server macros are not coming across to Fulcro 3, and so now the Fulcro server will be a typical Clojure web server with altered middleware. Here run-query is your own function and wrap-api comes from the require: [com.fulcrologic.fulcro.server.api-middleware :as fmw :refer [not-found-handler wrap-api]].

jimrthy04:08:23

That's awesome! Thank you, especially for the warning about the server-side changes.

cjmurphy06:08:54

You can then println inside run-query, and use the data structure you see there to query Datomic. i.e. run-query will be returning the result map that your Fulcro browser app has requested.

Abhinav Sharma17:08:48

Hello everyone, I was wondering whether anyone could point me to a reasonably sized fulcro project on Github? I have tried using a few keywords but perhaps some open projects have been shared in the channel earlier.

wilkerlucio17:08:39

hello, Fulcro Inspect is a good one to look

wilkerlucio17:08:00

altough the code is a bit old, has a descent scale

Abhinav Sharma17:08:16

Hmm, got it 👍 I guess, it using fulcro2 right?

✔️ 1
Abhinav Sharma17:08:22

Yup, it is. I was wondering if there are any plans for porting it to Firefox? The FF dev edition is quite decent as well and FF also changed their web extensions mechanism recently.

Abhinav Sharma17:08:56

@U066U8JQJ, thanks for the help!

wilkerlucio17:08:02

just no time to support, but would love to have, an old idea is also to have an Electron client, this way you can use on any environment (not just browsers, could be used for React Native for example)

👍 1
Abhinav Sharma17:08:52

Yeah, that sounds cool! I'll be going over the repo soon 🙂

matthavener18:08:49

has anyone here ever seen or looked into making a db->tree-like macro that takes a compile-time query and produces an optimized db->tree function?

wilkerlucio18:08:17

that wouldn''t work well, queries are dynamic and change all the time, also you have to re-process everything when data changes, so it can't be computed ahead of time. makes sense?

matthavener18:08:24

what changes your queries? In apps I work on we use stuff like set-query very rarely

wilkerlucio18:08:26

depend on the usage, you can for example use :update-query when you trigger a fetch/load, there you can update as query freely, another helpers like :focus and :without also do query manipulation. but really the point is more about you need the data, reading eql doens't take much time, what could be optimized here is the convertion between EQL -> AST, that can be more easily cached

matthavener19:08:16

ahh ok, I suppose fulcro modifies the queries more than expected. I would have asked this in #om but its fairly quiet in there

tony.kay01:08:28

performance-wise, F3's db->tree is really really fast

tony.kay01:08:45

it is unlikely to be the source of performance problems in a properly-written app

tony.kay01:08:24

it is roughly 6x faster to do query processing in F3 than 2. The react overhead is way more than the query processing in most cases.

👍 1
matthavener13:08:49

thanks for the insights, checking out this f3 implementation

tony.kay14:08:57

part of the improvements are in what F3 no longer has to do, but that f2 does

tony.kay14:08:19

path-meta was half of it, and is no longer needed.

tony.kay14:08:58

another chunk was adding time to the props as a post-step instead of during parsing (that is part of rendering optimization to know the time of the different bits of props).

tony.kay14:08:30

then the reimplementation sped up the core db->tree as well. So, overall the total overhead in processing the client UI query is dramatically less

winkywooster19:08:12

I've been following the fulcro3 tutorial, and section 3.6.2 (http://book.fulcrologic.com/fulcro3/#_step_1the_initial_state) it has an example of pulling the initial state from the repl. Question is which repl? I'm trying in both the shadow-cljs dashboard repl in the browser and the one created in Cursive, but I keep getting

(com.fulcrologic.fulcro.components/get-initial-state app.ui.root/Root {})
Syntax error (ClassNotFoundException) compiling at (REPL:1:1).
app.ui.root

currentoor20:08:25

is the cursive repl a CLJS repl?

currentoor20:08:52

you need a browser connected repl, provided by shadow-cljs

currentoor20:08:24

and maybe you need to load namespace you’re in?

Fabian20:08:11

i had a the same problem in the fulcro 2 book

cjmurphy02:08:50

I tried using a terminal from within Cursive with npx shadow-cljs cljs-repl main, and it worked fine. F5 in your Chrome browser if your app is not yet running.

winkywooster19:08:59

The various clj and cljs repls I still find a bit confusing