Fork me on GitHub
#fulcro
<
2022-03-24
>
aratare02:03:54

Hi there. Is there a way to configure storage strategy in fulcro, i.e. where all the data reside? I'm looking for a way to persist data between page reloads, and wondering if this is possible without me having to manually save after every load or mutation. Thanks in advance.

xceno08:03:00

So i haven't done this and I'm just speculating right now: In theory you could https://clojuredocs.org/clojure.core/add-watch to the the app atom and then perform your logic in there. This way you wouldn't have to modify anything.

sheluchin13:03:08

I wonder if this is something Pathom's cache/`core.cache` can be used for https://pathom3.wsscode.com/docs/cache/

aratare13:03:24

As far as I can tell, this is for server-side only? I'm looking for a more frontend-oriented solution in this case 🙂

aratare13:03:48

But thank you for the link, I'll prob use it as well on the backend.

👍 1
aratare13:03:14

@U012ADU90SW Thanks for the suggestion. I'll give it a spin!

Jakub Holý (HolyJak)16:03:07

An atom watcher is IMO a fine approach. If it is enough for you to only cache the server-provided data then you could have look at https://github.com/fulcrologic/fulcro/blob/develop/src/main/com/fulcrologic/fulcro/offline/load_cache.cljc

Jakub Holý (HolyJak)16:03:21

Hi @tony.kay! I saw this comment https://github.com/fulcrologic/fulcro-rad-kvstore/blob/master/src/main/com/fulcrologic/rad/database_adapters/key_value/duplicates.cljc#L2 and wonder whether you still plan to move the code into RAD proper. I also need it for my #asami DB adapter 🙂 Thank you!

tony.kay16:03:47

I’m game, just have not had the time

👍 1
tony.kay16:03:47

I didn’t write those exact versions, the docstrings need fixed, and we need to find the right ns for them, but the logic is reusable, so it’d be nice to get em in there

Jakub Holý (HolyJak)16:03:29

Anything I can help with?

tony.kay17:03:11

I’m not doing antying with it anytime soon. If you want it moved, give it a go 🙂

Jakub Holý (HolyJak)17:03:58

Ok, I will look at it. Thank you.

👍 1
roklenarcic08:03:15

That crap is busted and doesn’t work in CLJS.

roklenarcic08:03:05

I’ve fixed at least 3 bugs in fulcro-rad-kvstore and konserve and it still doesn’t work

roklenarcic08:03:19

that namespace in particular has bugs

roklenarcic08:03:36

this is a patch to fix the problem where the temp IDs are not correctly unwrapped to UUIDs. And even that is a bad idea because it makes assumptions about the structure of tempids, the correct thing would be to generate new UUIDs and return the tempid->new uuid map mapping

Jakub Holý (HolyJak)13:03:08

Isnt't structure of tempids fixed? That is what fulcros tempid fn return, no? I don't think Tony will change htat 🙂

tony.kay16:03:49

So, I didn’t write the kv-store, and have not tried it out…have you looked at the helpers in datomic-rad plugin?

tony.kay16:03:57

Ah, I see what you’re saying…the author tested against CLJ, but the CLJS-side isn’t right…that’s probably because the code was taken from the Datomic plugin, which is CLJ only.

roklenarcic13:03:49

Unfortunately that’s not the only issue there. i’ve wasted a bunch of evenings trying to get fulcro-rad-kvstore to work as frontend adapter with IndexedDB in CLJS. Another issue is that a specific function that can be sync or async (returning a value or value wrapped in async channel) depending on store, and it’s used as if it was always sync, and in CLJS it can only be async so that’s a show stopper right there. Then the acual serialization/deserialization of UUIDs to EDN is broken due to bug in Incognito, which erroneusly thinks cljs.reader/tag-table uses strings for tag, but it actually uses symbols

roklenarcic13:03:53

All in all it makes me think that the IndexedDB provider wasn’t tested even once.

roklenarcic13:03:03

Because there is no way it has every worked with 3 bugs that each cause a total failure of the “write a new entity, read it back” user story

tony.kay14:03:00

Perhaps @U0D5RN0S1 can comment on that. He’s the primary author.

tony.kay14:03:05

I’ve added a comment at the top of the README making the status of that plugin a bit more clear with a warning about CLJS support.

❤️ 1
cjmurphy19:03:34

Yeah my primary goal was to get the RAD Demo going, which is CLJ only. It worked well for me. I was encouraged to do the CLJS (which uses core.async) as well. But indexedDB was so terrible that I just left an alternative front end (https://github.com/fulcrologic/fulcro-rad-kvstore/blob/master/src/demo-project/com/example/ui/landing_page_2.cljs) to demonstrate the problems as clearly as I could. If you hook that one up (by referring to the -2 version rather than the landing_page.cljs version) then there's a series of buttons with output going to the browser console. In general I very much tried to follow the way the Datomic plugin did things, and as you can see I 'code documented' all the duplicate functions I had to use in a ns called 'duplicates'. Of the three bugs that you found @U66G3SGP5, is it possible to demonstrate any of them by using the RAD Demo? If so then that would be a cause for concern, as this library doesn't really make any of its own decisions.

njj19:03:08

Previously with defui you could create inner functions (like you would with a class), that could render things, onClick etc.. similar to how its done in React. Is this something you can do with defsc also?

tony.kay22:03:37

You mean the very old version of defui, which was protocol based?

👍 1
tony.kay22:03:20

so the :initLocalState is called like a constructor, and you could put methods on this . That’s kinda yucky. Such methods never could close over state in any way, so you can always write them as fn outside of the class. If you want something truly local you could: 1. Put them in component-local state (e.g. :initLocalState). 2. (preferred) Use react hooks.

tony.kay22:03:37

(defsc C [this props] {:use-hooks? true} …)

tony.kay22:03:24

(hooks/use-callback …)

tony.kay22:03:40

Hooks are really pretty nice

njj00:03:24

:thumbsup: hooks are definitely nicer

njj00:03:46

but yes, we are still on that super old defui - trying to migrate everything off now to defsc and have some components that use that old react style of having various functions inside the class. I’ve been just moving them out into smaller presentation functions/components, but wasn’t sure if there was some other way

njj00:03:20

Thanks Tony!

njj16:03:02

@tony.kay any ideas on what the equivalent for defsc would be for something like this?

njj16:03:04

(defui ListingTitle []
  static ISearchColumn
  (column-name [T _] "TITLE")
  (es-sort-fields [_ _] [:title])

njj16:03:41

Oh wait I think I found it in the docs:

njj16:03:42

(defsc MyComponent [this props]
   {:protocols (Object
                static css/CSS
                (local-rules [_] [])
                (include-children [_] []))
    ...}
   (dom/div ...))

tony.kay16:03:29

Jeez…I didn’t even remember that was there. That’s also an answer to your other question…..

njj16:03:47

Can’t wait to clean up all this old stuff 😅

tony.kay16:03:16

hm…no, protocols isn’t there anymore

tony.kay16:03:21

what version are you porting TO?

tony.kay16:03:58

you might be doing stuff that is still going to require a second pass

njj16:03:55

hopefully anything above 2.5.9

njj16:03:36

Is there an alternative to what I have that would work in newer versions w/o having to rewrite the way all of these work?

tony.kay16:03:21

Fulcro components are no longer protocol-based.

tony.kay16:03:45

The CSS stuff uses a newer version of that lib, that just uses plain keys in the options map

njj16:03:18

ok bummer, yeah I have a ton of stuff like this:

njj16:03:20

(defui ListingHost []
  static ISearchColumn
  (column-name [T _] "HOST")
  (es-sort-fields [_ _] [:ownerFirstName :ownerLastName])

  Object
  (render [T]
    (let [{:keys [ownerFirstName ownerLastName ownerId ownerAvatarId]} (get-computed T)]
      (dom/div
        (avatar-card T ownerId ownerAvatarId {:first ownerFirstName :last ownerLastName})))))

tony.kay16:03:44

Is as of Fulcro 3 the components are just low-level js functions. There are no types/protocols/etc. This helps with things like dead-code elimination, and also normalizes things. The options maps is completely open, meaning you can add any key to it you want (preferably namespaced) to have any meaning you want.

tony.kay16:03:10

So, you can put things like :es-sort-field on there, and the use component-options on the class OR instance to pull it out and use it.

tony.kay16:03:22

This is how RAD works, and it is a thing of beauty.

tony.kay16:03:08

So, you can just write some kind of wrapper helper for your “protocol” functions, which are tied to a ns, right? You could make es-sort-fields be a normal function in the ns where you used to declare ISearchColumn

tony.kay16:03:54

and it does: ((comp/component-options this :es-sort-fields) this args)

tony.kay16:03:00

with proper nil checks and such

njj16:03:50

I think so

njj16:03:59

let me give it a spin and see if I can things working

tony.kay16:03:14

(defsc ListingHost [this props]
  {:es-sort-fields (fn [this args] [...])}
  ...)

(defn es-sort-fields [this props]
  (when-let [f (comp/component-options this :es-sort-fields)]
     (f this props))

💡 1
njj16:03:54

ah interesting! Ok let me try to get this going

njj16:03:56

thanks again Tony

tony.kay16:03:22

sure, where that last function will accept this OR ListingHost

tony.kay16:03:29

it’ll work on both in Fulcro 3.x

tony.kay16:03:58

you’ll see that the new localized dom lib uses this exact pattern

njj16:03:45

gotcha, but I will first need to be on 3+

tony.kay16:03:35

I would not bother porting to 2.x…you’ll still be missing out on a lot of good stuff

tony.kay16:03:53

and you’ll have to redo a bunch of work because defsc evolved slightly, as you’re seeing, from 2

njj16:03:58

:thumbsup: