I am currently on an angular 1.x project, and we are about to add user interactions that will cause data changes.
We already identified some flows in our app that seem like flux might resolve, so we are going to use flux.
We don't yet know flux, and the libraries that exist today seem like an overkill.
We have an idea on how to implement it easily, and would like to hear from you if
- This is indeed a flux architecture we are building
- If the design we suggest will cause problems we cannot see now
- If there is a library that already implements it this way that we missed
- We would like to have a structure very similar to angular without flux.
- A directive interaction will call a service.
- The service will call the backend and return a promise
- All our bindings are one way ('<', '&')
- services will have an event registration mechanism (subscribe/unsubscribe).
- the directive that triggered the service will only consume errors if happened from returned response.
- service will dispatch event on success.
- directives will subscribe to events from services
- so a parent directive can apply the status change, and children directives will be updated with one way binding.
This is a high level description of how we would like to add flux to our system. There are more fine-grained implementation details that seem too verbose for this question such as how will the subscribe/unsubscribe mechanism will be implemented, but let us know if they are indeed relevant.
For now I am just using a simple implementation of unidirectional flow.
Basically directives expose function bindings like
onItemChange: '&' and some root directive for the page is in charge of handling operations and data manipulation (directly or with a service).
So it is quite straight forward, very angular, and good enough for scaling the code.