Fork me on GitHub
#fulcro
<
2019-11-30
>
noonian01:11:52

I'm playing around with fulcro-rad based off the example code and ran into an issue with defsc-form and wondering if it's just user error on my end. :form-fields ends up empty on the generated component options because the macro in form.cljc uses the clj attribute registry during macro expansion and since my ui is a cljs file only the cljs version of the attribute registry has been populated. If I (:require-macros [my-app.model.account]) in my ui it fixes the issue (because when the defattr forms are evaluated as Clojure they populate the clj registry used by the defsc-form macro). I'm curious how the example code is working because it does not :require-macros

tony.kay04:11:30

That is all experimental code, and will likely change, and will be documented when stable…but also see https://blog.fikesfarm.com/posts/2016-03-01-clojurescript-macro-sugar.html which might have something to do with your question…I don’t have time to analyze your case 🙂

noonian03:12:32

I understand what is going on and that the code is experimental. I will try and contribute a PR if I can get the macro to work in cljs files without evaluating the defattr forms in the jvm context as well as cljs. The use of :require-macros is just a hack to get the code working and I think this is the basic usecase of defsc-form. Thank you for the time and effort you put into fulcro

Jacob O'Bryant04:11:08

Has anyone deployed a fulcro app to datomic ions while using timbre? I'm running up against this error; not really sure what's going on: https://clojurians.slack.com/archives/C03RZMDSH/p1575089762024000

Philipp Siegmantel08:11:50

Hello, I'm getting an Unknown app state mutation. Have you required the file with your mutations? highlight-key-green error I can't figure out. My mutation looks like this

(defmutation highlight-key-green [{:keys [octave key]}]
  (action [{:keys [state]}]
          (swap! state
                 assoc-in [:keyboard/green-key]
                 {:keyboard/octave octave
                  :keyboard/key    key})))
and I'm calling it like this
app.client.core> (comp/transact! app '[(highlight-key-green {:octave 0 :key 0})]) 
The app.client.core namespace has the following ns clause
(ns app.client.core
  (:require [com.fulcrologic.fulcro.application :as app]
            [com.fulcrologic.fulcro.dom :as dom]
            [com.fulcrologic.fulcro.components :as comp :refer [defsc]]
            [sablono.core :as sablono]
            [app.client.keyboard :refer [PianoKeyboard ui-keyboard]]
            [app.client.mutations :refer [highlight-key-green highlight-key-red]]))
I'm guessing I'm doing something very obvious wrong, but I can't figure out what it is.

currentoor09:11:16

Use backquote instead of regular quote

currentoor09:11:22

Or no quote at all

Philipp Siegmantel09:11:40

That got rid of the error. Thanks.

currentoor09:11:05

With back quoting you can get around circular requires, invoking the sym directly requires you reference the mutation sym like calling a function

currentoor09:11:24

Either way it needs to be a namespace qualified symbol

Philipp Siegmantel09:11:27

OK. I will remember that.

Philipp Siegmantel10:11:33

Bear with me, I have another beginner question. I have a component with the following query {:query [:keyboard/green-key :keyboard/red-key]} . My state looks like this.

app.client.core> (app/current-state app)
{:keyboard/green-key {:keyboard/octave 1, :keyboard/key 1}, :com.fulcrologic.fulcro.application/active-remotes #{}, :keyboard/red-key {:keyboard/octave 2, :keyboard/key 1}}
Still, when I print out the components state, it is an empty map.

Björn Ebbinghaus12:11:34

Querys start from the root. The query works only on the root Component.

Philipp Siegmantel13:11:49

Thank you, it works now.

tianshu14:11:19

Is my usage correct? I use this df/load! to load the data for this component, but it looks a little verbose here. Especially I have to specify :target (which should be current component) and Customer (which already in my query).

(defsc CustomerModule [this {:keys [customers name-filter payment-type] :as props}]
  {:query [{:customers (comp/get-query Customer)}
           :name-filter
           :payment-type]
   :ident (fn [] [:component/id :customer-module])
   :initial-state {:customers []
                   :name-filter ""
                   :payment-type "all"}
   :route-segment ["customer"]
   :will-enter (fn [app route-params]
                 (df/load! app :customers Customer
                   {:target [:component/id :customer-module :customers]})
                 (dr/route-immediate [:component/id :customer-module]))})
I want to know if there's way to simplify how I load data for this particular component. And my :will-enter will always run 3 times for each time I change the route, but the render will happen only once. There maybe something wrong with my code, but don't know how to investigate deeper.

pvillegas1218:11:47

For loading data

pvillegas1218:11:58

use :componentDidMount, don’t do a df/load in :will-enter

Björn Ebbinghaus01:12:06

You can load in will-enter but you should use route-defered and target-ready afterwards. Will-enter will maybe be called more than once.

tianshu09:12:13

Hi, @U4VT24ZM3 How can I do two df/load! before target-ready? I saw in the example in document, it shows use post-mutation and post-mutation-params in df/load!.

Björn Ebbinghaus10:12:04

You can add call target-ready from inside your mutation. But I recommend that you think about what you actually have to load to display the Routing target. Load additional stuff elsewhere. If you need everything, than you should reconsider your query.

grounded_sage18:11:34

@tony.kay is it possible to make pull requests on the book? I'm not sure where the source is for it. Just finding some little typo's that would be easy to fix with a pull request.

currentoor18:12:10

PRs definitely welcome on that front 🙂

sheluchin18:11:32

Is there any place to read the Fulcro book in smaller sections, instead of having everything on one page? It's pretty slow to load on mobile, especially after I add some annotations to the page.

adamfeldman19:11:55

I don’t think it’s available

adamfeldman19:11:46

The slow-loading is likely due in-part to the inline live code examples.

adamfeldman19:11:24

On my iPhone, I was able to load the book in Safari, then use the share-sheet to open it with Books. This converted it into a static PDF in Books, albeit with a layout not optimized for mobile reading

tony.kay22:11:58

Be a great contribution: I don’t have time to maintain derivative works, but a mobile-friendly version of the book would be nice to have if someone wants to figure out how to make that happen and keep it up to date without any overhead for me.

currentoor18:12:34

@U066U8JQJ’s pathom docs recently did this, maybe @UPWHQK562 you could follow his example

sheluchin11:12:38

Indeed, I might take a look. For the while I'd like to focus on just learning Fulcro, but I think it might be a good exercise in getting things up and running somewhere. I don't think I'll have the time to go over it in December, but perhaps early in the new year.

👍 4