Fork me on GitHub
#fulcro
<
2017-10-19
>
alpox07:10:41

I’m not sure if this is fulcro related or not and i’m quite a beginner but i thought i give it a shot. I set up the leiningen fulcro template to make a few tests and tried to use “sablono” in it. I added sablono to the list of dependencies in project.clj (`[sablono "0.8.1"]`) and require it in root.cljc: [sablono.core :as html :refer-macros [html]]. When i start the server, it can initially render the page with sablono. Every subsequent change or restart of the server yields Unable to resolve symbol: html in this context though. Is there anything missing about the setup of the fulcro template to make the dependency stable?

alpox08:10:09

@fatihict ahh, awesome. That makes sense. Thank you :)

roklenarcic08:10:54

How can I wrap a mutation with another one? Fulcro bootstrap has show-modal and I'd like to have a mutation that basically wraps it and delegates to it.

fatihict09:10:17

Can you explain why you want to wrap that mutation?

roklenarcic09:10:39

I want to detect if modal wasn't initialized

roklenarcic09:10:56

basically I want to fill out init data for modal before each show-modal

roklenarcic09:10:26

I could do it as another mutation and list both mutations in the vector

roklenarcic09:10:37

[(prepare-modal) (show-modal)]

roklenarcic09:10:09

but now I have bunch of mutations with similar parameters and theres a lot of parameter duplication

mitchelkuijpers12:10:20

@roklenarcic If I run into that issue I just extract functions from the different mutationsand create a mutation that composes those mutations together calling the extracted functions.

tony.kay18:10:37

@roklenarcic What Mitchel suggests is also my suggestion (see Reference Guide). Of course, transact! itself accepts a sequence, so you can compose them at the UI layer, or behind the scenes at the mutation layer; however, mutations are intentionally structured to not be “nestable”. Nesting creates a lot of incidental complexity. Writing helper functions that accomplish tasks and using those in your mutations is better.

tony.kay18:10:58

Any State => State function can easily be composed into a swap! in a mutation (swap! state #(-> % (do-thing-a params) (do-thing-b params) ...)

roklenarcic18:10:41

I guess the only issue is when a mutation comes for a lib

roklenarcic18:10:53

then I can't break it up into a function

roklenarcic18:10:14

But I'll think of something, maybe a function that puts together the mutation vector

roklenarcic18:10:22

I guess that's one way to do it

tony.kay18:10:43

So, a library should always be written with composition in mind. For Fulcro they should supply both the mutation, and the helper function that works just on state.

tony.kay19:10:28

But you’re also correct in that nothing prevents you from writing modal-transact! that wraps some tx modification with a call to transact!

tony.kay19:10:40

or a data xform that works on txes

roklenarcic19:10:39

food for thought: have you considered enabling AST/reads optimizations server-side? This is not something I would need today, but thinking long term, I thought that it might come handy sometime in the future, to be able to optimize DB operations based on the whole query tree. Right now fulcro uses defquery-root as a point where you implement a read of a single key. But sometimes, you have multiple reads of the same type in or some other reads that can be processed in bulk. Like AST has read for number of people in the database and another key requested list of people with an empty filter. The second operation can also supply data for the first read. Just something I was thinking about when reading about these kinds of optimizations being done with GraphQL server-sides.

tony.kay19:10:22

So, the macros are just wrappers for a multimethod. On the server side the base primitive is the Om query parser (which you can in turn further wrap in whatever you want). Many applications will be fine with the macros and built-in parser, but more complex apps can already leverage the primitives instead in whatever way you want.

tony.kay19:10:13

See also @wilkerlucio’s work on pathom. He’s done some amazing stuff for building server parsers.

roklenarcic19:10:14

thx I'll look into it

tony.kay19:10:03

Yeah, he was just demoing something the other day where he has it turning graph queries into REST calls against Spotify REST API.