This is a response to Bill Fisher regarding experience with Flux:
@abdullin Also, can you clarify what you mean by "solution structure"? I am thinking about revising the examples soon.
Currently all flux samples (that I've seen) group files into folders based on technical similarity. For example, stores go with stores, action creators reside in the same folder shared with the other action creators.
This pattern works quite well for smaller projects. It feels especially good for the sample projects of various MVC frameworks, when you have just a bunch of controllers, models and views.
However, as we discovered on some production projects, such approach doesn't scale well. At some point you end up with dozens of technically similar files per folder and logically messy solution.
- Doesn't scale well.
- While you work on a component, you have to suffer from extra context switching overhead (jumping between various folders).
- Solutions become more "entangled" than needed.
- More complex IDE features are needed to support the workflow (e.g. context-aware navigation and completion).
- More merge conflicts, since it is harder to bound work by a feature (and communicate that).
We discovered that aligning solution with the domain model leads to a better design in the long run. E.g. we try to group files by their functionality or feature. This would mean, that different technical elements of a single feature could be squashed into one folder or onto one file. For example, for Flux we are considering to have a single folder for "News feed", which would contain all related action creators, fetchers and stores. Of course, there could be some other components that the this chat page would use (e.g. avatars, like buttons or user stores), such components would reside in their own folders. On the overall, such component decomposition is requires more effort than simply grouping files by class type. However, we value both the process (it leads to a deeper insight) and the outcome (solution that is more simple to think and reason about).
Of course, this is just something that seems to work only in a subset of cases I've been exposed to. There can easily be a deeper pattern which I fail to recognize.
Hi Rinat, Bill,
Thanks for these insights, they are very useful.
I was recently thinking more about actions/events in the past. Because I do love the idea the actions are outcomes of real-word processes and thus should be named in the past because they can't change. But I have some concerns about this, and I was wondering what you think about it.
Validating user input
At the moment my stores are responsible for the validation and I do something like this:
So it's possible that a message is not valid so submitted seems wrong here. It's only after the validation that the message really is submitted.
Failed on the server
An action can fail on the server, so, again, submitted seems wrong.
Possible solution
It's the responsability of the api (actionCreator) to call the server, and maybe also to validate the messages, so it would be possible to handle all things that can fail in the api and change my api interface like this:
for validation:
with submitting to the server:
The inspiration for my solution came mostly from here: http://www.code-experience.com/async-requests-with-react-js-and-flux-revisited/
This has the advantage that all actions can be in the past again, but it makes the solution more complex. Furthermore, as soon as localstorage is added, that could fail too and that must also be taken into account.
On the other hand, syncing between localstorage and the server is not trival, so dealing with it explicitly wouldn't be so bad.
Is this the way you would handle this, or do you do this differently?