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-03-06T00:06:10.182300Z

I think it is reasonable to add some kind of dev-time query check to Fulcro. I think the two critical paths that would not affect performance much would be at initial mount (which would get it on hot code reload too) and in set-query!. The latter one is used mainly by the dyn routers, so it would only cause a penalty on route changes.

tony.kay 2021-03-06T00:07:51.182500Z

I’m also feeling like we should have better errors around missing :initial-state. That seems to trip people up a lot. It would also be possible to add macro checks to defsc that could find stupid errors on compile. It can’t expand the get-query calls, but it could look for obvious mistakes, like a call to get-query that isn’t embedded as a value in a map, a map that has more than one key, and other such obvious mistakes.

tony.kay 2021-03-06T00:08:52.182700Z

the check, for that matter, could sub calls to functions that have get-query in their name with [:subquery-of-ComponentClassName] and run a spec check on the resulting expression.

tony.kay 2021-03-06T00:09:47.183100Z

of course such a check would have to “bail” if there were other function calls in there

tony.kay 2021-03-06T00:10:21.183300Z

and syntax quoting from user space would cause possible problems….but I think you could catch a lot of common cases

tony.kay 2021-03-06T00:11:25.183500Z

@holyjak you have any interest in working on that? I’d be glad to give you some pointers if you’re willing to do the legwork/testing

tony.kay 2021-03-06T00:12:54.183800Z

This is on Fulcro 2

tony.kay 2021-03-06T00:19:35.184Z

I’m not actively maintaining F2. If you want to submit a patch to fix this, please branch from the fulcro-2 branch, and send a PR targeted at that branch.

tony.kay 2021-03-06T00:20:22.184200Z

You’ll need to upgrade dependencies and test it. If you can certify that it looks good, I’ll push an update to clojars.

Jakub Holý 2021-03-06T00:28:20.186800Z

Hello! https://github.com/holyjak/fulcro-troubleshooting has been extended (v5, latest) to check initial state (even in lambda form) for validity and to wrap user components with error boundary so that an exception during render does not blow up the whole up. Please give it a try! https://github.com/holyjak/fulcro-troubleshooting/blob/master/CHANGELOG.md#v5---2021-03-06

👏 3
🎉 1
Jakub Holý 2021-03-06T00:29:49.187100Z

yes, I do!

Jakub Holý 2021-03-06T00:32:52.187300Z

Speaking about the dev-time query check on mount etc. would it be (s/explain ::eql/query query) ? As explained above, I think we would also need to check during app/set-root! b/c it is called before mount and fails it there are errors. BTW how do we know it is dev time? goog.DEBUG?

tony.kay 2021-03-06T01:20:08.187900Z

I think the error message would be better if we just did a valid? and indicated that the query was not valid EQL. We might use explain-data from there and try to narrow it down, but I would not use explain. (when goog.DEBUG …) is the proper wrapping for it, since that will cause dead code removal in advanced compile. And yeah, set-root! seems a good place as well. In the macro, I was thinking of replacing any function calls whose symbol name is get-query as I explained above, then look for any other things that are lists that start with symbols. Then, if there are NO other symbols (recursive check) in the query, then it should be ok to check the resulting EQL and throw a syntax error. That would be way more noticeable than an error in the console.

tony.kay 2021-03-06T01:21:47.188200Z

I’m considering adding a default initial state with a join on every query edge for components with constant idents…if you wanted to try your hand at that as well 😄

tony.kay 2021-03-06T01:22:27.188400Z

hm, not sure that one is possible. It’s hard to detect if the ident is constant…nvm

tony.kay 2021-03-06T01:23:15.188600Z

some kind of runtime check around initial state seems like a good idea, I’m just not sure what it is. I can’t tell you how many times someone’s error/question is purely a matter of they didn’t set up initial state for their component.

Jakub Holý 2021-03-06T07:04:47.189Z

>. I can't tell you how many times someone's error/question is purely a matter of they didn't set up initial state for their component. When is that a problem? I thought it only is critical for https://book.fulcrologic.com/#_a_warning_about_ident_and_link_queries and router targets (and all their ancestors)?

Jakub Holý 2021-03-06T15:22:08.191800Z

Seeing https://codesunaba.netlify.app/, would it be possible to make a fork with Fulcro? It is macro-heavy but I suppose the macros do not necessarily need to use any CLJ JVM specific code. What do you think, @tony.kay ? It would make creating interactive, hands-on Fulcro tutorials much simpler 🙂

tony.kay 2021-03-07T18:42:34.201300Z

It’s actually come up a few times as a desire (it would be cool). If memory serves correctly it isn’t just Fulcro that’s the problem…the macros actually are not that hard to port. The bigger problem was that it has a spiderweb kind of effect, where all of the dependencies have to be bootstrap compatible. So, something as simple as logging (we use timbre) cause issues, because those dependencies are also not bootstrap compatible.

👍 1
Marcus 2021-03-06T16:21:53.193900Z

app.ui=>  (comp/get-initial-state app.ui/Root {})
------ WARNING - :undeclared-var -----------------------------------------------
 Resource: :1:25
 Use of undeclared Var app.ui/Root
--------------------------------------------------------------------------------
{:friends {:list/label "Friends", :list/people [{:person/name "Sally", :person/age 32} {:person/name "Joe", :person/age 22}]}, :enemies {:list/label "Enemies", :list/people [{:person/name "Fred", :person/age 11} {:person/name "Bobby", :person/age 55}]}}
I am going through the getting started section in the fulcro book. Do you know why this happens? (defsc Root ...) is in this ns and the returned map is correct.

Jakub Holý 2021-03-06T16:42:30.194800Z

happens to me sometimes as well. I solve it I think by reloading the ns. ClojureScript repl has its mysteries...

Marcus 2021-03-06T17:08:21.195Z

hehe ok thanks 🙂