Fork me on GitHub
#fulcro
<
2018-07-04
>
currentoor00:07:23

ah i see what you mean

wilkerlucio00:07:43

you can do: (prim/transact! reconciler [:my-ref "123"] ['(delete-package)]

wilkerlucio00:07:05

then you get it in the key :ref in the environment

wilkerlucio00:07:16

I have lots of generic functions that work using this abstraction

wilkerlucio00:07:45

because the ref gets to be the "data address"

wilkerlucio00:07:04

so I think as: "Im targeting this identity here, and my operation works from it"

wilkerlucio00:07:31

and threat it like a graph, a node with other references, and the transaction ref gets to be the starting point of the operation

currentoor00:07:52

yeah that seems like a solid approach, i'm gonna do some refactoring now simple_smile

wilkerlucio00:07:42

cool, you can get some examples on those in fulcro inspect source, this is one I use very often: https://github.com/fulcrologic/fulcro-inspect/blob/develop/src/client/fulcro/inspect/helpers.cljs#L45-L48

currentoor18:07:16

thanks i'll take a look simple_smile

tony.kay01:07:54

I’ll toss in my 2 cents here…why aren’t those things normalized??? If they’re normalized, then they are always in the same spot, even in devcards. Oh, you mean you want to throw the component itself just in a devcard. To me, these are different mutation helpers that are composed into the mutation, and if you really intend to use the sub-component separately from the parent (as in a devcard or elsewhere in the UI), the I code a mutation in the devcard that just uses the mutation helper for the sub-component.

tony.kay01:07:24

or write the helper that deals with the parent to be tolerant of the parent missing

tony.kay01:07:02

At the core of your question, @currentoor, seems to be the notion of composition of components, and how that affects mutations. If I have a “reusable” component, and I want to compose it, then what do I do? The answer for parent-child relationships should always be the same: react callbacks. The parent should handle the delete, and the child should simply have an onDelete. The update-in in your delete-package is misplaced IMO. GC is another issue, but the fact is when you “delete” something from the UI, the main thing you need to delete it from is the “owner/parent”. Cleaning out the tables may or may not make sense depending on what else refers to it. If you happen to know that the item really is toast, then the parent’s mutation can clean that up, too. This, to me, means that the child is never an “active” component in a devcard-fulcro without either being in there with the parent, or having some local card logic written with the cards.

currentoor18:07:43

well said, i'll mull over this

currentoor18:07:18

@wilkerlucio's suggestion of just using more idents seems quick and easy, and looks like it would work alright just on it's own

currentoor18:07:23

you're approach seems like better architecture (if i understand it correctly)

currentoor18:07:08

are you saying the update-in should be in a different mutation (call it update-table? then both [(delete-package ...)(update-table ...)] mutations should be passed in as a call back to the modal with the delete button?

currentoor18:07:45

then update-table mutation could be co-located with the table component

currentoor18:07:00

yeah that seems better

tony.kay21:07:42

I write each "unit of functionality" that I need in mutations like this:

(defn delete-item* [state-map list-id item-id] ...)

(defmutation delete-item ...  (swap state (fn [s] (-> s (delete-item* list-id item-id) ...))))

tony.kay21:07:04

then I can re-use (and compose) those "mutation helpers" (which I annotate with a trailing *) in any mutation

currentoor23:07:49

so do you co-locate mutations with UI components?

currentoor23:07:58

or put them in a separate section?

tony.kay04:07:32

And I sometimes put an atom in mutation namespaces so I can get around the circular require...defsc followed by a reset to put the component into a diff ns, since it is convenient to alias the mutations into the component ns, but you can't go both ways in clojure...

souenzzo02:07:58

Hello. I'm trying to use material-ui with fulcro dom, I dont know exactly how to. I tryied something like this, but I'm getting problems with props.

(:require [material-ui :as m])
(def grid (prim/factory m/Grid))

tony.kay05:07:01

See Shadow-cljs user’s guide, particularly the bits about how to require js stuff

tony.kay05:07:37

I’ve not used material ui myself, but it really boils down to getting the require right

tony.kay05:07:09

I think you want (:require ["@material-ui/core/Button" :refer [Button]])

tony.kay05:07:25

and you don’t use prim factory, that is for Fulcro components

tony.kay05:07:01

see the Fulcro Developer’s Guide…search for factory-apply…essentially you’re going to need to invoke react’s createElement

souenzzo12:07:20

I will try this apply. The require part is already ok, I'm using the "webpack method"

souenzzo12:07:05

Nice! Working. I will try to write a gist about how to use material-ui with fulcro, including the jss with-styles. 🙂

Daniel Hines12:07:47

@souenzzo, I'd love to see that gist when you're done!

souenzzo18:07:06

@U8QTB156K I will not have many time for the next days. I "dumped" the setup here. please ask/comment 🙂 https://gist.github.com/souenzzo/7f376efca955660e6221bca7827164ba

Daniel Hines18:07:22

Thanks a bunch!

souenzzo18:07:50

+jss/withStyles on fulcro

souenzzo18:07:37

+jss on reagent

chrisblom12:07:50

we would like to add error tracking to our app, to track when a mutation or read fails, is there a hook in the parser to track exceptions?

chrisblom15:07:15

Nevermind, we noticed all parser errors are logged using fulcro.logging/error, so we will use a custom logger to intercept the exceptions and forward them to our error tracker

fatihict14:07:44

Hello, I need help with the following case I want to solve: 1. Client side fetch ids from an external API 2. Fetch entities based on those ids from my server 3. Perform another request to the external API to update a count I tried to solve this by writing my own remote which can read and mutate the external API. I used ptransact like so

(prim/ptransact! reconciler `[(fetch-ids-from-external-api) ; [1] does a df/load-action and sets df/remote-load for the external remote
                              (fetch-my-entities-based-on-those-ids) ; [2] does a df/load-action and sets df/remote-load for my remote
                              (another-call-to-the-external-api-which-updates-the-count)]) ; [3] only has a remote
For some reason the load-action from [2] doesn't fetch entities from my server. I also don't see a call in my network tab in my developer tools or errors/warnings in my console. If I remove [1] or [3] I do see a call to my server in my network tab. I don't understand what I am doing wrong here. P.S. I can't use fulcro-inspect to test or debug this issue because I am in an iframe.

wilkerlucio15:07:43

@fatihict had you though about doing the count update on the server side instead?

wilkerlucio15:07:30

and which version of inspect are you using? if you do 2.2+ you probably can use on iframe (since it's a devtool, I haven't tested so I would be glad to hear if works on iframe situations, but my guess is that it should work)

fatihict15:07:03

@wilkerlucio I chose to do the count update client side because I don't want my server to be busy with those calls (which can potentially be a lot). And I am on the latest version of fulcro-inspect 2.2.0-beta8. I can confirm that it does not work with an iframe with the message "Your client library is stale. Please upgrade to Fulcro Inspect 2.2.0-beta8" in the "Fulcro Inspect" tab

wilkerlucio16:07:38

that warning doesn't affect the functionality, it's something I add to be sure the client is updated (since the chrome ext will update automatically anyway)

wilkerlucio16:07:50

but thanks for reporting, can you please open an issue? that might be something solvable

wilkerlucio16:07:58

and about ptransact, this needs some debugging, had you tried logging things, the mutation [2] isn't called at all?

fatihict17:07:57

I opened an issue for fulcro-inspect and the mutation [2] is being called, I do see logging I put there in my console, but no call in my network tab :thinking_face:

currentoor19:07:17

@wilkerlucio just wanted to check my understanding of this function, resolve-path https://github.com/fulcrologic/fulcro-inspect/blob/develop/src/client/fulcro/inspect/helpers.cljs#L29 it takes paths like [:tab :singleton :package] and gets the data at the end of them, if the result is an ident it will resolve it and get the actual data?

wilkerlucio19:07:27

@currentoor it returns a path, but it resolves idents during the resolution, so you can walk the graph

tony.kay21:07:13

@fatihict Did you read the docstring of ptransact? The WARNING section about using it with things that only read, and using multiple remotes?

tony.kay21:07:39

Fulcro discourages this kind of client behavior, but if you're going to do it, then I'd use post-mutations, and issue real loads from a setTimeout 0 (since post mutations don't do remote processing). I have not officially settled on a cleaner solution to this need, but it is a clear need that comes up on occasion. Partly it isn't "solved" because people are too used to using it where they shouldn't in Fulcro...I could easily add official remote support to post mutations from loads to solve this. Just know that it is perfectly fine to do a load with a post-mutation by having the post-mutation's action do: (js/setTimeout #(df/load ...) 0).

tony.kay21:07:05

transact and ptransact are meant for mutations (writes) that can potentially return data of interest. ptransact!, in particular, is meant to use the returning function on the remote side to return data, not issue load-actions.

tony.kay21:07:18

The common use-case for ptransact! is form processing where you want to be sure the server "has it" before moving on. This is the "mutation with returning" (read after write) with a post-processing step.

tony.kay21:07:10

But at the end of the day, this kind of "load chaining" is something I discourage. Personally I'd prefer to send a query to the server, have it do the request to the external API to get the IDs, gather the entities, update the count, and then return the entities (and count if needed) to the client.

tony.kay21:07:36

Then again, I know that criteria out of our control makes it necessary to sometimes do this kind of thing, in which case I use the setTimeout trick to issue "top-level" loads against the reconciler (which is in the load env).

wilkerlucio22:07:27

@tony.kay I suggested @fatihict he can also just split the process in more transactions, so the loads can go in between instead of using load-action, the setTimeout problem is that it can't chain on a remote response, so I think ptransact! still needed in those cases

tony.kay22:07:42

@wilkerlucio sure it can load :post-mutation with setTimeout