Fork me on GitHub
#fulcro
<
2019-06-23
>
namelos04:06:18

Hi, I’m trying to fill Fulcro in the bucket of my head… In the tutorial there’s two PersonLists and each PersonList have multiple Persons. There are two PersonLists so they all have ident. What if I just have a global singleton list, can I have a normalized result without given the singleton an identity? More specifically the following code:

clojure
(defsc TodoItem [this {:keys [db/id todo/text]}]
  {:query         [:db/id :todo/text]
   :ident         [:todo/by-id :db/id]
   :initial-state (fn [{:keys [id text]}] {:db/id id :todo/text text})}
  (let [delete #(transact! this `[(delete-todo-item {:id ~id})])]
    (div
     (span text)
     (button {:onClick delete} "-"))))

(def ui-todo-item (factory TodoItem {:keyfn :todo/text}))

(defsc Root [this {:keys [ui/react-key todos]}]
  {:query         [:ui/react-key
                   :todos (get-query TodoItem)]
   :initial-state (fn [params] {:todos [(get-initial-state TodoItem {:id 1 :text "first"})
                                        (get-initial-state TodoItem {:id 2 :text "second"})
                                        (get-initial-state TodoItem {:id 3 :text "third"})]})}
  (map ui-todo-item todos))
would result the following database:
clojure
{:other-keys ...
 :todos
 [{:id 1 :text "first"}
  {:id 2 :text "second"}
  {:id 3 :text "third"}]}
So there’s no :todo/by-id table I declared in the query of TodoItem. If I remove the level of :todos it seems I have to put entities at the top level without table. Am I doing it wrong or if I need top level normalised entities table I have to provide identity all the way down to the entities I want to normalise?

Gcf06:06:36

Is there any documentation out there about installing and running falcro on windows? I made an attempt, but was unable to successfully run shadow-cljs. After some research it seems like the configuration that comes out of the lein template is incompatible with windows.

thheller07:06:49

@clojuriansinvite how so? I'm on windows myself

hmaurer15:06:00

is windows decent these days for development? or do you have masochistic tendencies?

thheller16:06:56

I'm pretty happy with it

Gcf17:06:20

@U5ZAJ15P0 Since Azure became Microsoft's #1 priority Windows development has massively improved, and will continue to improve. That being said, I'm on windows because I wont buy Apple, and there is a lot of software I like to use that does not run on Linux.

Gcf18:06:02

@U05224H0W. When I try to run shadow-cljs, it complains it can't find clojure. This is despite clojure definitely being on my system path.

Gcf18:06:08

shadow-cljs - starting via "clojure"
Executable 'clojure' not found on system path.

Shan18:06:08

@clojuriansinvite if you run clj in your terminal, does that work?

Gcf18:06:20

Yes, running both clj and clojure in the terminal works

thheller19:06:06

ah right. yeah the clj and clojure versions on windows are something powershell related

thheller19:06:14

dunno how to call that properly

thheller19:06:46

works fine if you just use plain shadow-cljs.edn without deps.edn

thheller19:06:51

or WSL works too

Gcf07:06:18

@U05224H0W I've been using WSL in the mean time, but I would prefer it if I could avoid it.

thheller07:06:37

it sort of depends on the missing clojure executable. I need to look at how the powershell implementation works since I don't know why thats different

thheller07:06:48

but I should be able to detect it somehow

cjsauer21:06:08

Think I figured out the above by using prim/with-parent-context to thread this through to my wrapped Fulcro components, but now I have a different issue. Root’s query looks like {:current-screen (prim/get-query Screen)}, and then my individual screens are querying for [:screen/id], with ident [:screens/by-id :screen/id]. Essentially what’s happening is that by using ident/link queries on :current-screen from root, mutating that value is causing root to re-render (obviously), but this is stepping on react-navigation which apparently assumes it has control of root rendering. I believe I might need to make use of the reconciler’s shared-fn to store :current-screen, and then each screen can “root themselves” on that shared state. I can hook into react navigation’s events in order to set :current-screen…is this an acceptable use of shared-fn :thinking_face: