Is there any documentation on the new fulcro statecharts integration yet? I am running into an issue as I convert my app from dynamic routing to statecharts.
ok, so I’m playing with this again. There was definitely a little tinkering to do still. I’ll push a snapshot update later tonight. The setup was definitely having problems with certain app structures, and I’m pretty sure I still don’t have it right, but I had already forgotten what one bit of the code was for (like what was I thinking?). I’ve got my own application partially ported and am working out the RAD issues, and adding a little automation into the statecharts integration so it can at least auto-detect forms and reports for initialization purposes so you don’t have to plunk down options on them. I didn’t really want the statecharts lib to end up having a ton of deps on Fulcro stuff, so I may need to just make a new library…if I add in RAD helpers we’re moving rapidly towards making it have all the deps. But for now since you’re playing with it I am personally using these two functions to make states for reports and forms, though I still need to think about the cleanest way to “leave a form”, since the routing is kind of built-in right now (you can override the control button).
(defn report-state [props]
(uir/rstate (merge {} props)
(on-entry {}
(script-fn [{:fulcro/keys [app]} data _ event-data]
(log/info "Starting report")
(report/start-report! app (comp/registry-key->class (:route/target props)) event-data)
nil))))
(defn form-state [props]
(uir/rstate props
(on-entry {}
(script-fn [{:fulcro/keys [app]} data _ event-data]
(log/info "Starting form" event-data)
(let [{:keys [id params]} event-data]
(form/start-form! app id (comp/registry-key->class (:route/target props)) params))
nil))))
where the intention is to use uir/route-to! and send params as event data. For forms this would mean sending event data with at least :id, where you use a tempid for new, and a real id for edit.
1.2.9-SNAPSHOT
I got this mostly working and then realized that it won't work for what I originally envisioned. Since the statechart is started in the app database, it's tied to the browser. I wanted to have a statechart running in clj, like the web server so it would run all the time and execute it's states and events even if a browser is not loaded. Then I could load the browser for a UI front-end to access data from those states and show it to the page. It seems currently the app is only in cljs, and the statechart is unloaded when I close the browser window.
When you say you are running on the client and the server, are you creating a statechart simple env in clj for the server side statecharts? I have the statechart working from the app database in cljs, but really want to run it from clj so closing the browser does not unload it.
So, the statecharts lib has pluggable everything. event queue, data model, execution model, session store, and even main algorithm. So, I’ve written a durable event queue in CLJ using a PSQL database, and also use SQL as the session store. So, there’s a thread that watches for events on the sql queue, loads the relevant session, runs the event(s) on it, marks the events delivered and saves back the session store. So, long running CLJ statecharts.
of course you have to make sure you make compatible changes to such a long-running chart (e.g. the existing configs for running charts must be compatible with a new version). An alternative is to version your charts (so that the session store knows what version of the chart to use when running events)
I have been thinking about the dependency problem you described for fulcro and fulcro-rad. Is there a reason you are creating the integration code in the statecharts lib? For instance if I am wanting to use fulcro with statecharts, I am opting into the fulcro dependency already. Ditto for fulcro-rad. I would expect the integration code to be in fulcro, or fulcro-rad, or a third library just for integrations, that can be included when needed from the fulcro/rad app. I am currently using statecharts for a stand-alone service, and I have very fulcro-ish app setup there purely in clj with the simple environment ns from statecharts. I do not use fulcro or fulcro-rad for this at all currently. Making statecharts depend on fulcro and/or fulcro-rad would bring deps into my project that does not need them. I'm sure you've thought all this through, just commenting because I have given it some thought myself for my own app.
I just don’t want to make and maintain yet another lib. Technically this should be statecharts-fulcro, which then has fulcro and statecharts deps, but then do I make statecharts-fulcro-rad as well? Seems to me just putting the nses in statecharts, and if you use one of these nses, then you manually add the dependency you need.
The statecharts and Fulcro and RAD libs are all CLJC, but you’re right that my ui routing experiments are somewhat directed at UI, but then there is nothing really that requires they be in a browser, and it is all cljc…so, technically you can make a headless Fulcro app and run it in CLJ without a UI. But I’m not sure what you’re looking for exactly. I run statecharts in both places (server and client), and I’ve thought about ways in which you might want to make that “boundary-less” but have not implemented anything.
The possibilities are quite large. You could have a statechart running on the server and use mutations to send events to it, and the return value of the server chart mutations could be the current configuration.
or you could have a websocket system where you make the same statechart on front and back run at the same time, and send the same events to them. If the server trggers an event it is copied (ws push) to the client and vice versa…sort of keep them in sync, but the server chart does server things, client does client things.
etc
com.fulcrologic.rad.form/create! is not routing to the statechart route, it appears to be attempting to do a dynamic route, not a statechart route. Not sure what I am doing wrong, I am using the statecharts demo repo to try to model my conversion, but that does not have any examples of forms at all, just simple routes. Using this example demo repo: https://github.com/fulcrologic/fulcro-with-statecharts/ My latest code is here: https://gitlab.com/michaelwhitford/gailish
I also have questions about how to utilize a statechart without a ui, I have a working statechart in another app that opens a websocket (chatbot) and would like to incorporate that setup into this app, but not seeing anything about how to use a statechart in fulcro that doesn't have a UI. My websocket states all work very well currently to reopen the connection on error, and do some setup if that connection is restarted.
the docs are the demo app…it is considered alpha, so please know you are in experiment land
Statecharts are not tied to Fulcro in any way. The fulcro integration is just for convenience. You found the manual for statecharts? I wrote one.
It is pure CLJC with very few actual deps at the low level.
the event queues, data model, and even execution model are something you can implement via protocols.
RAD integation (forms) is NOT part of the statecharts stuff I’ve wrtten, but stop using RAD routing, and instead put the forms/reports in as rstates, and add an on-entry handler that starts the UISM. See docs on forms/report use outside of dyn routing
you’ll have to add the correct params to the start functions (e.g. start-form with a create option, or and edit with uuid)
for the time being you will lose the saving or report params to URL…but that is doable with a fix the the UISM machine for reports
Yes I have a pure statecharts service running as a chatbot tied to a slack-like chat system. It runs great. I am wanting to run most of it under fulcro to give my chatbot service a UI where I can monitor the chats, and create analytics. I have read through the statecharts guide a few times now and just re-read the fulcro integration part. My main sticking point is how to get a rad form to route correctly. i have top level routes working ok, but anything where I try to do a form/create! just does not route, it seems to do nothing. I see no transactions at all from Inspect.
right, you cannot use form/create
as I said above
you have to use form/start-form! instead
and report/start-report!
those do NOT do routing…they just start them, wihch is what you need in this case
form/create! is a convenience function for doing routing AND starting the UISM
Ahhh, ok thank you very much I will look at that. I am excited to get the statecharts into fulcro, thanks for all the work that went into this integration.