biff

A web framework + self-hosted deployment solution for Clojure. Repo: https://github.com/jacobobryant/biff. Docs: https://biff.findka.com
2020-09-01T02:25:15.026600Z

Just looked through domino-clj's readme. Hadn't seen it before. Looks interesting. Your Intention and Theory sections both seem on track to me. For your questions: > What are the steps that I need to do to add a new table of 'facts' (or any other datatype)? I follow roughly these steps, using the :public-users (i.e. public information about a user) table from the example app: 1. Define a spec for the datatype (https://github.com/jacobobryant/biff/blob/f368d110bc35e52ff293d8306627eeac429fee66/example/src/example/rules.clj#L13 and https://github.com/jacobobryant/biff/blob/f368d110bc35e52ff293d8306627eeac429fee66/example/src/example/rules.clj#L10) 2. Define rules for the datatype, which reference the spec and also include authorization functions (https://github.com/jacobobryant/biff/blob/f368d110bc35e52ff293d8306627eeac429fee66/example/src/example/rules.clj#L33) 3. Subscribe to the datatype on the client (https://github.com/jacobobryant/biff/blob/f368d110bc35e52ff293d8306627eeac429fee66/example/src/example/client/app/db.cljs#L55) 4. Set up reactions for the datatype (https://github.com/jacobobryant/biff/blob/f368d110bc35e52ff293d8306627eeac429fee66/example/src/example/client/app/db.cljs#L30) 5. Use the datatype in the UI (https://github.com/jacobobryant/biff/blob/f368d110bc35e52ff293d8306627eeac429fee66/example/src/example/client/app/components.cljs#L33) 6. Set up mutations for the datatype (https://github.com/jacobobryant/biff/blob/f368d110bc35e52ff293d8306627eeac429fee66/example/src/example/client/app/components.cljs#L36 and https://github.com/jacobobryant/biff/blob/master/example/src/example/client/app/mutations.cljs#L23) > should I be thinking about biff as starting point to using crux, or as an open-source firebase? > When should I use crux directly? I don't quite understand the first question, but I think the answer is "the former". (I went with "tables" mainly for personal aesthetic taste and because it's shorter to type). Generally speaking, Biff provides a layer of abstraction on top of Crux. That abstraction layer gives you (1) subscriptions, (2) integration with rules, (3) some higher level operations in transactions (e.g. :db/merge). But there likely will be times when you want to bypass Biff and use Crux directly. For transactions, I pretty much always go through biff. I haven't documented it, but there's a biff.crux/submit-tx function (https://github.com/jacobobryant/biff/blob/f368d110bc35e52ff293d8306627eeac429fee66/src/biff/crux.clj#L522) which lets you submit biff transactions from the backend as a trusted user. The changes will be checked against the specs for your table to make sure you didn't make a mistake, but the authorization function (which verifies that the current user is allowed to submit the transaction) won't run. However if going through biff feels like an annoyance, it's easy enough to use crux.api/submit-tx instead. Biff's query support only includes subscriptions, not one-time queries, and it supports a very limited subset of Crux's query features. So I always use crux.api/q when querying on the backend. It could also be useful on the frontend (via a custom sente event handler/http handler) if you need more complex queries and you can live without Biff's subscription support. I have a branch of Findka that does that for paginating some queries (Biff doesn't have a pagination story at the moment). > Do I need to edit handlers.clj with a custom handler new type, or is there a standardized way of doing it with biff?

2020-09-01T02:25:15.026700Z

Not necessarily. If all the frontend's writes can be authorized easily using the rules system, then you can just submit biff transactions from the frontend; no need for setting up custom event handlers. This is often the case for CRUD apps. However, some writes, like complex state transitions, are easier to handle with a custom event. Since the example app is a board game, it includes these kinds of writes. In general, adding custom handlers in Biff apps is more of a one-off thing, not something you do whenever you add a new datatype. (Let me know if I misunderstood this question).

rainbow_bamboo 2020-09-01T14:34:29.028Z

Thanks for your response and clarifications ^_^ I think that you pretty much addressed all my queries.

👍 1
➕ 1