Fork me on GitHub

All right: I’ve been threatening to show how to integrate Clara Rules with Fulcro for some time now, and I just did a demo that works pretty well in RAD, though RAD is by no means required. In fact, the way it works is really quite simple: • I add a watch to the state atom. When it triggers it saves off the current old state map (only if it has not done so since the last refresh), and schedules a rules run. • I use the old/new state map snapshots to figure out, for a list of Fulcro tables, which things have appeared/changed/disappeared • I convert the Fulcro db table entries that are “tracked” into Clara Fact records • I fire the rules • I run queries against the rules session to get the desired changes • I push those changes to the Fulcro DB.

👍 44
fulcro 8
❤️ 16

it only took about 80 lines of code to get the general Fulcro integration.


The rest is app-specific. This particular demo is for an invoice, where there is a calculated subtotal.


You could use that exact code in any Fulcro app, and just do an (install-rules-engine! app) in client-did-mount.


of course you’d have to adjust your tables and rules


My performance measurements using Chrome performance tab shows the update and rules run takes about 18ms. Not sure how adv builds might improve that, and how that might scale (since the RETE algorithm is meant to be efficient at updates).