Fork me on GitHub
#fulcro
<
2018-11-29
>
tony.kay02:11:46

I just released Incubator 0.0.21 with nested trigger support in state machines. You can now trigger events on other state machines from within a SM handler. Docs updated and added a workspace example. https://github.com/fulcrologic/fulcro-incubator

❤️ 8
levitanong19:11:32

Awesome! Would this also work for the same state machine?

tony.kay19:11:17

yes, but since you can run code and activate a new state from a handler, not sure why you’d do that 🙂

levitanong19:11:56

Just a curiosity 😛

levitanong19:11:40

say, is it idiomatic to move logic to over to the state machine, or is it preferable to keep as much logic in mutations as possible (and then calling the trigger! from the mutation)

tony.kay19:11:22

I see state machines as a mega mutation…when I use them, I don’t end up with mutations much at all. I call trigger from the UI

tony.kay19:11:48

I also recentlhy added apply-action, which lets you use state-map functions (i.e. mutation helpers, which I generally annotate with a * suffix).

tony.kay19:11:10

the handler is essentially the optimistic data update, and the trigger-remote... stuff is for remoting

levitanong19:11:13

oh, that’s great! i’ve been wanting to move more logic to the state machine. I just read somewhere in the docs that the mutations handle the optimism

tony.kay19:11:31

oh….point that out to me, I should fix it

levitanong19:11:54

i took a look at the part where i thought i saw it

levitanong19:11:07

and it seems consistent with what you’re saying now. I must’ve misread it!

levitanong19:11:44

i wonder, is it sane to use the begin event-data to transmit relevant classes?

tony.kay19:11:05

classes? That is what actors are for

tony.kay19:11:20

if you have need of some UI concern, add that UI bit as an actor

levitanong19:11:25

i am aware that the docs suggest actors for it, but i have a lot of different classes for different purposes

tony.kay19:11:35

still, that’s how you should do it

levitanong19:11:18

last i tried to use it, it always complained if i didn’t include an ident

tony.kay19:11:20

you could technically pass anything in the event data, but do not pass code unless you put it in metadata, since it can end up in your state, and affect serialization

tony.kay19:11:33

sure, but you can “make up” an ident

levitanong19:11:56

yeah, that’s what i ended up doing. It felt like i was cheating haha

tony.kay19:11:51

nah…just do something like (def CLASS-ONLY [:FAKE :IDENT]), and then it will be clear in your code 🙂

tony.kay19:11:04

(uism/with-actor-class CLASS-ONLY Boo)

levitanong19:11:14

so i have another question

levitanong19:11:54

given that all this machinery is to avoid circular dependencies, is there any story for functions?

levitanong19:11:33

for example, if i wanted a google map to change its view after some remote thing happened

tony.kay19:11:33

story? I don’t understand

levitanong19:11:58

and some function exists in that namespace that performs that job

levitanong19:11:34

rather than redefine that function, i’ve been passing it in event data, which i realize will put the function inside app state

tony.kay20:11:04

so, part of that is just a need to organize your code well. I agree that in Clojure this is a bit of a pain. Mutation declarations were added in incubator as a way to help with this: you can declare your mutations in some “leaf” ns (and not require anything else), so that you completely avoid circular refs (and syntax quoting , for that matter). But if you’re getting circular refs on code, it indicates you need to refactor your code. Move the functions that have no deps to new leaf nses, then move the next layer to their own, etc.

levitanong20:11:33

that makes sense

tony.kay20:11:48

If you feel you must pass things through fulcro like this, then at least do something like this: (with-meta {} {:some-fn (fn [] ...)}) for your parameter

tony.kay20:11:59

serialization doesn’t “see” metadata

tony.kay20:11:10

so you can safely pass classes, functions, etc. that way

tony.kay20:11:27

I do it in some implementation things when it is necessary (not usually for circ refs, but it does come up)

levitanong20:11:31

i think your first point is the way to go. I’ll just make yet another utility namespace 😛

levitanong20:11:58

thanks for your advice 😄

levitanong20:11:35

oh one last thing!

levitanong20:11:50

regarding aborting

levitanong20:11:29

there is mention of using abort-request, but the said function has the application as a parameter

tony.kay20:11:52

read the docs 🙂

levitanong20:11:33

i’ve read both the sm and fulcro docs, however, and it seems i either need the app or the reconciler inside the state machine

levitanong20:11:38

if i want to use fc/abort-request! from inside the state machine, i’ll need the app. But that seems like an unavoidable circular dep, and i do get stack overflow errors when i attempt it.

tony.kay20:11:54

put the atom in some leaf ns

tony.kay20:11:59

set it in started-callback

tony.kay20:11:05

use it anywhere you need to abort

levitanong20:11:41

thanks again 🙂

currentoor04:11:14

@tony.kay why can’t the actual UI root have an ident?

wilkerlucio16:11:24

because then know do you know what the root is? you need something to point to that entity, I always use a helper to generate roots (my actual components are never roots, all of then are ident based, but when build I can run a function that generates a root for it)

wilkerlucio16:11:31

maybe that helper could be included in Fulcro

wilkerlucio16:11:46

here is the helper:

(defn make-root [Root]
  (fp/ui
    static fp/InitialAppState
    (initial-state [_ {::keys [root-state] :as params}]
      (merge
        {:fulcro.inspect.core/app-id app-id
         :ui/root                    (or (fp/get-initial-state Root (dissoc params ::root-state))
                                         {})}
        root-state))

    static fp/IQuery
    (query [_] [{:ui/root (fp/get-query Root)}])
    static cssp/CSS
    (local-rules [_] [])
    (include-children [_] [Root])

    Object
    (render [this]
      (let [factory (fp/factory Root)]
        (dom/div
          (factory root))))))

wilkerlucio16:11:59

then you can turn any component into a root

wilkerlucio16:11:21

or maybe this could be automatically done by Fulcro if the root component contains an ident :thinking_face:

currentoor19:11:25

@U066U8JQJ thanks for sharing

tony.kay18:11:10

what is the ident of the root of the db?

tony.kay18:11:14

root is root. ident = table entry…how can it be root AND a table entry