fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
tony.kay 2021-04-25T01:50:45.235700Z

Laziness is the likely culprit. React forces things in dev but not prod.

Mikey OBrien 2021-04-25T15:30:08.239100Z

I’m having some issues figuring out how to store upload percentage in the state db to be used by a component. The code uses amplify-js which takes a callback. I have no issues logging the percentage out but don’t know how to display it in the UI. Any suggestions?

(defn- calculate-upload-progress [progress]
(let [percentage (.floor
                    js/Math
                    (* 100
                    (/ (.-loaded progress)
                        (.-total progress))))]
    (log/debugf "Upload Progress: %d" percentage)))

(defn upload-file
"supports the upload of a single file"
[{:keys [file real-id job-id string-columns job-name app]}]
(go (let [key-path (gstring/format "uploads/%s.json" job-name)
            resp (<p! (.vault.put Storage key-path
                                (js/Blob. #js [file])
                                (clj->js
                                {:metadata         {:string-columns string-columns
                                                    :job-id         (str real-id)}
                                    :progressCallback calculate-upload-progress})))]
        (try
        (comp/transact! app [(update-job-status {:id real-id :url "" :status "Converting..."})])
        (comp/transact! app [(set-loading {:uploading false})])
        (catch js/Error err (js/console.log (ex-cause err)))))))

Jakub Holý 2021-04-26T08:49:22.252900Z

Make a mutation for it and transact it from the callback, no?

(defn calculate-upload-progress [component pct]
  ...
  (m/set-integer! component :ui/progress :value pct))

...
:progressCallback (partial calculate-upload-progress component)
...
and just propagate this from the component that should display it. (Alternatively, use the global APP and transact! with a mutation that will set the value where you want it.)

👍 1
Mikey OBrien 2021-04-26T18:55:10.260800Z

Thank you. That makes sense.

2021-04-25T15:44:25.244300Z

I am investigating why cljs.pprint is being included in a release build of an app I'm working on. To start out with good known starting state, I cloned the fulcro template from (https://github.com/fulcrologic/fulcro-template) and see that cljs.pprint is included in the release build for the :main build of that template: As far as I can tell pprint is not included anywhere directly in the codebase and there are no obvious indications of namespaces that would include it transitively. I created the report by running: ./node_modules/.bin/shadow-cljs run shadow.cljs.build-report main report.html I'm going to continue removing namespaces from requires to see if I can get pprint removed, but I'm wondering if anyone else ran into this?

2021-04-25T16:50:04.245300Z

I'm not sure, but I think fulcro itself may be including it. I put together a small reproduction here: https://github.com/dvingo/fulcro-release-build-incl-pprint

❤️ 1
tony.kay 2021-04-26T13:22:09.254500Z

This is all on the TODO list. There is already a stubs file for guardrails that you can swap out via “resolve” cljs settings.

tony.kay 2021-04-26T13:25:20.255Z

It isn’t a super high priority for me, because the apps I work on really don’t care that much about hyper-optimizing build size. People put jpgs on their sites that are bigger than the diff between simple and the best optimizations possible, so it is very very very low on the TODO list to do anything more about this, other than accept very well-tested PRs.

thheller 2021-04-26T13:33:19.255400Z

yikes please don't use :resolve for this. that this actually works (if it does) is a bug, it shouldn't affect how CLJS namespaces resolve. for CLJS you should use the :ns-aliases option, same result really. see the example for re-frame-10x :build-options :ns-aliases https://github.com/day8/re-frame-10x#easy-setup

thheller 2021-04-26T13:36:24.255800Z

I'd push back a little on the jpeg argument. while it is true that over-optimizing for size is not super relevant in many cases the extra JS is significantly more expensive and impactful than an extra oversized image. eliminating a lot of code that is unused anyways can noticeably affect load performance, especially on lower end hardware or mobiles/tablets.

thheller 2021-04-26T13:37:17.256Z

I've done optimizations taking load times from 3sec to 500ms just by code splitting intelligently and removing unused code

2021-04-26T13:50:43.256200Z

Thanks for the reply @tony.kay I understand for some use cases this doesn't matter, but there are plenty of valid use cases where it does (I'm sure you're well aware https://web.dev/why-speed-matters/) Is this TODO list publicly visible? It would have been good to know about it before I spent the hours investigating this.

2021-04-26T13:52:07.256500Z

Thanks for the tip Thomas - I'll try out the stubs feature and see how it goes

tony.kay 2021-04-26T14:02:24.256700Z

@thheller thanks for looking. I thought that worked, but part of the reason that ns is marked alpha is because I wasn’t sure the comment was right, and hadn’t had time to research it again.

tony.kay 2021-04-26T14:08:17.256900Z

Docstring and README updated.

tony.kay 2021-04-26T14:09:08.257100Z

On load times. Yeah. 2.5s for an SPA you load once and run for hours. Just don’t care.

2021-04-26T14:09:55.257800Z

That is not the only use case of all uses of fulcro

tony.kay 2021-04-26T14:11:58.258Z

And the optimization paths are available to you. Obviously I care enough that you are able to follow those paths. When I say I don’t care, I mean I don’t care for my personal use-cases, and 90% of the ppl I’ve seen optimizing for this shouldn’t either.

tony.kay 2021-04-26T14:13:06.258200Z

there are some cases where it matters, but too many people go down this rabbit hole on prod software while their users are screaming for real fixes to real problems they have, and I guarantee you no one has lost a customer for a 2.5s load delay on an app they run all day.

tony.kay 2021-04-26T14:13:50.258400Z

Unless “reloading” that app is something they have to do a lot for some reason. Not saying there are not valid cases. Just that most ppl don’t have them.

2021-04-26T14:15:03.258600Z

This kind of viewpoint would be good to document in the fulcro documentation "The author doesn't care about page load performance caveat lector". fwiw A https://www.ericsson.com/en/press-releases/2016/2/streaming-delays-mentally-taxing-for-smartphone-users-ericsson-mobility-report shows that the stress response to delays in mobile speed are similar to that of watching a horror movie or solving a mathematical problem, and greater than waiting in a checkout line at a retail store. Not everyone is building a a SPA that is loaded once and used all day. Please stop assuming that.

tony.kay 2021-04-26T14:41:23.258900Z

Please re-read what I said. I am neither assuming that nor limiting your ability to fix that. I have spent a lot of time…meh. I don’t have time for these kinds of discussions. Sorry I chimed in on this one, to be honest.

2021-04-26T14:58:02.259700Z

Yep. Agreed. Sorry to waste your time.

tony.kay 2021-04-26T17:03:56.260500Z

no worries. It happens. Esp on Monday morning 😛

nivekuil 2021-04-25T19:21:03.245800Z

do you expect expound to be there too? I think that may be coming from guardrails?

2021-04-25T19:23:53.246Z

I do not expect that to be there -and spec.gen is probably not either. This is for a release build so guardrails should be disabled

thheller 2021-04-25T19:37:55.246200Z

cljs.pprint is not DCE capable so just requiring it will keep it in the build, even if otherwise unused

nivekuil 2021-04-25T19:39:03.246400Z

there's this section in the guardrails readme https://github.com/fulcrologic/guardrails#clojurescript-considerations

nivekuil 2021-04-25T19:39:36.246700Z

> > Doing so will prevent you from accidentally generating a release build with guardrails enabled in case you had a shadow-cljs server running in dev mode (which would cache that guardrails was enabled) and built a release target: >

2021-04-25T19:44:33.246900Z

You can try for yourself using that repo - I'd be happy to know if I'm doing something wrong, but there's one namespace in the project so it's hard to see what that would be

2021-04-25T19:44:57.247100Z

guardrails is not even in the dependency list (aside from fulcro including it transitively)

2021-04-25T19:45:45.247400Z

I would also expect other projects to see this showing up

thheller 2021-04-25T20:25:41.248700Z

what do you mean? fulcro directly requires guardrails, which means all the dependencies that has will be in your build

thheller 2021-04-25T20:25:56.249100Z

disabling guardrails does not change that, it only affects the code the macros generate

rukor 2021-04-25T20:26:40.250Z

hi, newbie question here. is save-middleware the best place to insert business logic such as set the owner of the object to the currently-logged-in user? I want to avoid having to do that on the front end.

Jakub Holý 2021-04-26T08:43:45.252700Z

Not sure but it sounds reasonable to me 🙂

rukor 2021-04-27T13:16:12.261100Z

thanks

rukor 2021-04-27T13:17:10.261300Z

handled it that way and actually worked out nicely that I could do it as a more general save-middleware with actual actions taken pre/post/save specified via attribute options on the entity identity attribute

❤️ 1
rukor 2021-04-25T20:26:47.250200Z

using RAD

2021-04-25T20:35:29.250300Z

I am seeing cljs.pprint and expound and fulcro.client-inspect etc show up in the shadow.cljs.build-report for a clojurescript project that uses fulcro. I do not understand why this is happening, so I posted the above git repository to make it easy for others to verify. Just requiring and rendering a fulcro application with one fulcro component results in those extra namespaces showing up in the build report.

2021-04-25T20:38:34.250500Z

Are you saying it is expected that cljs.pprint would show up then? That that is the cost of using fulcro?

thheller 2021-04-25T20:42:43.250700Z

if there is something requiring it in the build then yes it is fully expected. I don't know WHAT is requiring it but it seems like it is

thheller 2021-04-25T20:43:13.250900Z

you can reconstruct it from the compiler data but there is not function available currently do that for you

2021-04-25T20:48:45.251200Z

got it - thanks for the explanation. I believe a likely candidate is expound: https://github.com/bhb/expound/blob/46b5c84bfe578a81b07c39501a9ed60cfd6ed09f/src/expound/printer.cljc If there isn't much fulcro can do about this perhaps it can at least be documented. It would be good to know if it is intentional or not, or perhaps there is a way to prevent the inclusion of these with some code changes or config changes to one or all of fulcro, guardrails, and expound

thheller 2021-04-25T20:50:19.251500Z

my guess would be that it just hasn't been optimized yet, maybe just some namespace reordering would fix it already