1

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

The idea

Start point:

  • 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 ('<', '&')

Flux changes:

  • 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.

Temporary Solution

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.

  • I think you need to develop how will you use those directives that call services. Usually, it's the controller of the current page/state (ui-router) that subscribe to events and handle relations with services. – Walfrat Dec 13 '16 at 12:12
  • Yes.. so everything is directives in this project. So the controller of the page is a controller of a directive just the same. This is exactly the reason we decided flux was needed here. – guy mograbi Dec 13 '16 at 16:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.