Fork me on GitHub
#pathom
<
2019-04-10
>
souenzzo20:04:11

[{(foo {}) [:bar]}] cant return {foo [{:bar 1} {:bar 2}]}. Pathom always suppose that the return of a mutation is a map. Is it intentional?

wilkerlucio20:04:48

@souenzzo yup, that's by design, you see that everywhere, inputs must be maps, outputs must be maps, params must be maps, this is all intentional to force things to always compose (allowing extra things) and forces everything to be labelled

👍 4
souenzzo20:04:11

foo isn't a label? [{(:foo {}) [:bar]}] can return {:foo [{:bar 1} {:bar 2}]}

wilkerlucio21:04:37

yes, but your response data also must be labeled

wilkerlucio21:04:58

eg: {:person/id 123}, in this case 123 is labeled as :person/id, if it was just 123, no label

wilkerlucio21:04:05

its about context independence, makes sense?

wilkerlucio21:04:07

specially if you consider mutation joins, if the mutation return wasn't a map it couldn't be extended

souenzzo21:04:20

It's a problem with #fulcro. I my component

(fp/defsc Chat [_ _]
  {:query [:chat/id
           {:chat/msg (fp/get-query Msg)}]
   :ident [:chat/id :chat/id]})
Then I have a mutation [(load-older {:msg/id older-msg-id})] It is called with (fm/returning Msg) This mutation need to be (df/prepend-to [:chat/id id :chat/msg]) So it generate [{(load-older {}) [:msg/id ...]}]

souenzzo21:04:28

When I do [{(load-older {}) [{:older [:msg/id ...]}]}], but this way, I can't merge correctly in fulcro state

wilkerlucio21:04:44

are you using mutations to load data? any reason to don't use fulcro df/load?

souenzzo21:04:09

ATM I'm using df/load But once it will be called by "many" places, I thought that wrap it in a mutation makes sense. It also have some effects: set ui/loading? true, if returns empty, set final? true...

wilkerlucio21:04:54

fulcro load use the markers, I really suggest you keep using load, you can have wraps around it, but using mutations for data fetching goes off the semantics of the system... but anway, since you are adding multiple items to a list, there is no default helper in fulcro that will save you, when you load a resource its expected it directly maps to whatever component you are loading, but the modal doesn't have anything pre-made for specific injections (add this N items to a list), for those you will need a post-mutation anyway

souenzzo21:04:26

I will try to use df/load again

wilkerlucio21:04:47

for pagination I have some set of helpers that do what you want, but they require post-mutations to be involved

wilkerlucio21:04:35

(fm/defmutation merge-page-items [{:keys  [abrams.page/items]
                                   ::keys [page-key]}]
  (action [env]
    (db.h/swap-entity! env update-in [page-key :abrams.page/items] #(into items %))))

(defn load-next-page [this {::keys [page-key load-config]}]
  (let [ref           (fp/get-ident this)
        state         (-> (fp/get-reconciler this) fp/app-state)
        cursor        (-> (fp/props this) page-key :abrams.page/next-cursor)
        current-items (get-in @state (conj ref page-key :abrams.page/items))
        load          (merge {:query                [{ref [(-> (fp/get-query this)
                                                               (fp/focus-query [page-key])
                                                               first
                                                               (list {:abrams.page/cursor cursor}))]}]
                              :post-mutation        `merge-page-items
                              :post-mutation-params {:abrams.page/items current-items
                                                     ::page-key         page-key}}
                             load-config)]
    (fp/transact! this [(list 'fulcro/load load)])))

👍 4
souenzzo13:04:44

com.wsscode.fulcro.db-helpers is on workspace dir. It not public (i think that can be) But I'm having progress. tnks

wilkerlucio14:04:51

that db-helpers are internal on our project to be honest, but most of it is already ported in incubator 😉

👍 8
wilkerlucio21:04:41

something like this ^^^^

wilkerlucio21:04:12

in my case all paginations use the :abrams.page/items standard, this way I can write generic pagination components that work across many different resources