re-frame/docs/FAQs/DoINeedReFrame.md

88 lines
4.1 KiB
Markdown
Raw Normal View History

### Question
2017-10-21 12:02:12 +11:00
Reagent looks terrific. Why do I need re-frame? It looks like extra layers and
conceptual overhead for not much benefit!
### Answer
2017-10-21 10:49:23 +11:00
First, I agree, Reagent is terrific. If your application is small and simple,
then standalone Reagent is absolutely a fine choice.
But it only supplyiesthe V part of the traditional MVC triad. When
your application gets bigger and more complicated, you'll need to
find solutions to questions in the M and C realms. Questions like "where do I put control logic?".
And, "how do I manage state?". And, "How do I put up a spinner
when waiting for CPU consuming computations to run?" How do I ensure
2017-10-21 12:27:11 +11:00
efficient view updates? How do I write my control logic in a way that's testable?
2017-10-21 12:06:51 +11:00
How should new websocket packets be communicated with the broader app? Or GET failures?
These questions accumulate.
Reagent, by itself, provides little guidance and, so, you'll need to
2017-10-21 10:49:23 +11:00
come up with your own solutions. The choices you make will accumulate too and,
2017-10-21 12:02:12 +11:00
over time, will become baked into your code base,
becoming increasingly difficult to revisit.
2017-10-21 11:49:18 +11:00
Now, any decision which is hard to revisit later is an architectural decision -
2017-10-21 12:17:42 +11:00
"hard 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.
So, then, the question becomes: is your architecture better than re-frame's? Because
that's what re-frame gives you ... an architecture ... answers to the
2017-10-21 12:06:51 +11:00
various questions you'll face when developing your app.
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!
I think problems only arise when this process is not conscious and purposeful. You
can accelerate quickly with Reagent and get a bunch of enjoyable early wins, but then
ultimately end up off the road, in the paddock, because of
one of the corners leading up to a bigger application.
2017-10-21 10:35:03 +11:00
I've had many people (20?) privately say to me that's what happened to them. The real
number would obviously be much higher. And that's pretty much the reason for
this FAQ - this happens a bit too often.
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
"Reagent is all I need", because one way or
another you'll be using "Reagent + a broader architecture".
2017-10-21 11:31:59 +11:00
### Some Choices Made By re-frame
2017-10-21 12:02:12 +11:00
1. Events are cardinal. Nothing happens without an event.
2017-10-21 12:17:42 +11:00
2. Events are data (which means they are loggable, and can be queued, etc)
2017-10-21 12:02:12 +11:00
3. Events are handled async (A critical decision. Engineered to avoid core.async problems!)
4. For efficiency, subscriptions (reactions) should be layered and de-duplicated
2017-10-21 12:17:42 +11:00
5. Views are never imperative or side effecting (best effort)
2017-10-21 12:02:12 +11:00
6. Unidirectional data flow only, ever
7. Interceptors over middleware. Provide cross cutting concerns like logging and debugging.
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-10-21 11:49:18 +11:00
Hmm. I feel like I'm missing a couple, but that's certainly an indicative list.
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 -->