fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
Cristian Saucedo 2021-03-27T02:05:39.181Z

I have a situation where I have a relationship in one of my models in mr frontend fulcro db with a 1 to 1 relation ship with another model, something like

{:person/id 3
  ...
  person/pet [pet/id 5]}
The other model (`pet` in this case) does not contain this relationship because it seems redundant. If I have several of both of these types of records, what would be "right" way to derive the inverse relationship (being able to go from pet/id to person/id. I have a few questions about some possible solutions. • Is there a way to query this from the db? I know something like this would be possible in Datalog, but EQL documentation didn't mention anything simillar • Is there a way to create state derived from other state within fulcro? Something that would listen to the person/id map and derive a mapping from pet/id to person/id. I've done this before in re-frame, though their implementation is not super performant • Am I completely off base and I should just add the person/id relationship to the pet model. Even if #3 is the way to go, if there are ways to do #1 or #2 it would be great to know.

tony.kay 2021-03-27T06:24:13.181400Z

Three is the intentional design because it is performant, simple, and trivial to implement

👍 1
tony.kay 2021-03-28T04:03:34.197300Z

The design is an intentional one: The database and EQL are intentionally naive, and just walk a literal graph. This is a performance and clarity decision. If you want to choose a local database with more capabilities that is more feature rich, you are certainly capable of doing that. Everything from rendering to transaction processing is pluggable. You’re living in a world of distributed systems. Cache invalidation is just a thing you have to cope with, so choose your poison 🙂

Aleksander Rendtslev 2021-03-28T11:55:19.199200Z

What would be your suggestion here? An additional remote? or plugging in a new rendering and transaction handler? It definitely makes sense! I'm just trying to understand the downsides/upsides of each approach

tony.kay 2021-03-28T19:02:52.199500Z

My suggestion is to not complicate your code. use pathom to generate edges where you need them, query that from the server, and don’t worry about it on the front-end at all if you can.

tony.kay 2021-03-28T19:03:09.199700Z

don’t make some complex thing in the distributed side of the app

tony.kay 2021-03-28T19:03:50.199900Z

query for things from the server when you need them, let pathom connect the dots, use them as naively as possible on the front end

tony.kay 2021-03-28T19:04:30.200100Z

anything else is a dramatic increase in complexity. I guess if you find a real need to do that, you can of course…YMMV

Aleksander Rendtslev 2021-03-29T00:26:40.202400Z

Thank you for the perspective! I think letting it be remote only right now makes sense for my current stage. Being local/offline first is going to be critical, but your thoughts makes it obvious. I'll solve that later

tony.kay 2021-03-27T06:25:42.181600Z

You can implement reverse lookups by creating indexes, which is how datomic does it. There is nothing in fulcro that does that for you

tony.kay 2021-03-27T06:26:46.181800Z

There are plenty of places where could hook in such a thing, probably as a custom transaction processing plugin based on the included one

tony.kay 2021-03-27T06:27:05.182Z

Would make the most sense

Timofey Sitnikov 2021-03-27T12:39:03.188400Z

Good Morning all, If I do this:

(ns app.myns
  (:require
    [com.fulcrologic.fulcro.dom :as dom]
    [clojure.pprint :refer [pprint]]))

(pprint (div :.ur.blah))
I get this:
#js {"$$typeof" #object[Symbol(react.element)], :type "div", :key nil, :ref nil, :props #js {:className "ur blah"}, :_owner nil, :_store #js {}}
How does Fulcro turn declared div into a function?

donavan 2021-03-27T14:05:33.189100Z

It’ll help you to watch these videos to understand what dom/div is doing https://www.youtube.com/playlist?list=PLVi9lDx-4C_TBRiHfjnjXaK2J3BIUDPnf

Timofey Sitnikov 2021-03-27T18:55:50.189600Z

@donavan, the mystery I am trying to solve is how the dev declaration converts to a function in the source. Its in this namespace: https://github.com/fulcrologic/fulcro/blob/develop/src/main/com/fulcrologic/fulcro/dom.cljs

donavan 2021-03-27T18:56:40.189900Z

There is both a macro div and function div . Is that what you’re talking about?

Timofey Sitnikov 2021-03-27T18:59:42.190100Z

Possibly, but in the source, you simply (dev :.ui.main), where is the div declared as a function or macro looking at the fulcro.dom source. Sorry, I am pretty new to Clojure and trying to figure out how things work.

Timofey Sitnikov 2021-03-27T19:00:24.190300Z

This is probably more of just Clojure question.

donavan 2021-03-27T19:00:34.190500Z

right, i think what’s confusing you is it’s generated in a macro

donavan 2021-03-27T19:01:24.191300Z

And this creates the client side js function version https://github.com/fulcrologic/fulcro/blob/develop/src/main/com/fulcrologic/fulcro/dom.clj#L240

donavan 2021-03-27T19:01:53.191600Z

If you’re not so sure about what a macro is then, yes, it’s a clojure question 🙂

donavan 2021-03-27T19:05:32.191800Z

I would watch the videos I posted above… as far as I remember Tony touched on this stuff

Timofey Sitnikov 2021-03-27T19:05:35.192Z

OK, so basically all of the declared values in dom.cljs are converted to functions using the macros. Therefore, all of these functions will have the same arguments.

donavan 2021-03-27T19:05:52.192200Z

Yeah, they all behave very similarly

donavan 2021-03-27T19:06:04.192400Z

The macros create the functions at compile time

donavan 2021-03-27T19:06:45.192600Z

…well the one macro creates the macro versions and the other macro creates the function versions

Timofey Sitnikov 2021-03-27T19:06:53.192800Z

Actually, I am not far enough into it to understand the videos. I am working up to it. Trying to understand some basic things. Also, I tend to learn much better after I dig into coded and understand it.

donavan 2021-03-27T19:07:47.193Z

Yeah, I wouldn’t worry about all this macro stuff… just use them, there’s a lot to learn before worrying about how the dom macros/functions are created

donavan 2021-03-27T19:08:14.193200Z

Any way, good luck. I’m off for supper

Timofey Sitnikov 2021-03-27T19:08:19.193400Z

Yeh, I am beginning to see how Tony layers the macros. Thats crazy, he is super smart.

Timofey Sitnikov 2021-03-27T19:08:32.193600Z

Thank you and enjoy supper.