re-frame/docs/FAQs/DoINeedReFrame.md

91 lines
4.2 KiB
Markdown
Raw Normal View History

### Question
2017-11-21 23:04:04 +11:00
Reagent looks terrific. So, why do I need re-frame? What benefit
is there in the extra layers and conceptual overhead it brings?
### Answer
2018-01-09 12:59:18 +11:00
Yes, we agree, Reagent is terrific. We use it enthusiastically ourselves. And, yes, we'd agree that if your application
2017-11-21 23:04:04 +11:00
is small and simple, then standalone Reagent is a fine choice.
2018-01-09 12:59:18 +11:00
But it does only supply the V part of the MVC triad. As your application
gets bigger and more complicated, you *will* need to find solutions to
2017-10-30 22:19:28 +11:00
questions in the M and C realms.
2018-01-11 20:16:29 +11:00
2017-10-30 22:19:28 +11:00
Questions like "where do I put control logic?".
2018-01-11 20:16:29 +11:00
And, "how do I store and update state?".
2017-11-21 23:04:04 +11:00
And, "how should new websocket packets be communicated with the broader app"? Or GET failures?
And, "how do I put up a spinner
2017-10-21 16:19:56 +11:00
when waiting for CPU intensive computations to run, while allowing the user to press Cancel?"
2017-10-21 14:51:10 +11:00
How do I ensure efficient view updates? How do I write my control logic in a way that's testable?
These questions accumulate.
Reagent, by itself, provides little guidance and, so, you'll need to
2017-11-21 23:04:04 +11:00
design your own solutions. Your choices will also accumulate and,
over time, they'll become baked into your codebase.
2017-10-21 11:49:18 +11:00
Now, any decision which is hard to revisit later is an architectural decision -
2017-11-21 23:04:04 +11:00
"difficult to change later" is pretty much the definition of "architecture". So,
2017-10-21 11:49:18 +11:00
as you proceed, baking your decisions into your codebase, you will be
incrementally growing an architecture.
2017-11-21 23:04:04 +11:00
So, then, the question is this: is your architecture better than re-frame's? Because
that's what re-frame gives you ... an architecture ... answers to the
2017-11-21 23:04:04 +11:00
various challenges you'll face when developing your app, and mechanism for implementing
those answers.
2017-10-21 11:49:18 +11:00
Now, in response, some will enthusiastically say "yes, I want to grow my own
architecture. I like mine!". Fair enough - its a fun ride!
2017-11-21 23:04:04 +11:00
Problems arise ONLY when this process is not conscious and purposeful. It is a
credit to Reagent that you can accelerate quickly and get a bunch of enjoyable
2018-01-11 20:16:29 +11:00
early wins. But, equally, that acceleration can have you off the road
in a ditch because there are twists and turns on the way to a larger application.
2018-01-11 20:16:29 +11:00
I've had many people (20?) privately say to me that's what happened to them.
And that's pretty much the reason for this FAQ - this happens a bit too often
and there been a bit too much pain.
2017-10-21 10:35:03 +11:00
So, my advice is ... if your application is a little more complicated,
2017-10-21 12:27:11 +11:00
be sure to make a conscious choice around architecture. Don't think
2017-10-30 22:19:28 +11:00
"Reagent is all I need", because it isn't. One way or
another you'll be using "Reagent + a broader architecture".
2017-11-21 23:04:04 +11:00
### Example Choices Made By re-frame
2017-11-21 23:04:04 +11:00
1. Events are cardinal. Nothing happens without an event.
2. Events are data (which means they are loggable, and can be queued, etc).
2017-11-23 06:14:31 +11:00
3. Events are handled async (a critical decision. Engineered to avoid some `core.async` issues!).
2017-11-21 23:04:04 +11:00
4. For efficiency, subscriptions (reactions) should be layered and de-duplicated.
5. Views are never imperative or side effecting (best effort).
6. Unidirectional data flow only, ever.
7. Interceptors over middleware. Provide cross cutting concerns like logging and debugging.
2017-10-21 12:02:12 +11:00
8. Event handlers capture control and contain key code. Ensure purity via coeffects and effects.
9. State is stored in one place and is committed-to transactionally, never piecemeal.
2017-11-21 23:04:04 +11:00
Hmm. I feel like I'm missing a few, but that's certainly an indicative list.
2017-10-21 11:49:18 +11:00
re-frame is only about 500 lines of code. So it's value is much more in the honed
choices it embodies (and documents), than the code it provides.
2017-10-21 11:31:59 +11:00
2017-10-21 11:28:04 +11:00
### What Reagent Does Provide
2017-10-21 11:28:04 +11:00
Above I said:
2017-10-21 11:31:59 +11:00
> Reagent, by itself, provides little guidance ...
2017-10-21 11:28:04 +11:00
which is true but, it does provide useful building blocks. If you do want to create
your own architecture, then be sure to check out Reagent's `track`, `reaction` and `rswap`.
There's also other Reagent-based architectures like [keechma](https://github.com/keechma/keechma) and
2017-10-21 11:31:59 +11:00
[carry](https://github.com/metametadata/carry) which make different choices - ones which may
2017-10-21 11:49:18 +11:00
better suit your needs.
***
Up: [FAQ Index](README.md)      
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<!-- END doctoc generated TOC please keep comment here to allow auto update -->