mercredi 11 novembre 2015

How to slice my form to modules correctly in AngularJS?

I am trying to create one form for my big application. I wouldn't explain specific of the form and its functions. I will try to tell about it abstractly.

I have question about modularity. I will describe pros and cons of my variants and the question will be what is correct structure of this form.

I have form. This form will add some entity to the DB. I have 3 main parts on this form. I have container, main B module, A module and C module. C and A depend on B module.

This is structure of my form:

enter image description here

Proccess:

  1. Input some data in B module
  2. If data OK modules A and C are being shown

So A and C are hardly depend on B module.

I have two ways to perform this (from this moment I will talk about modules in AngularJS (controllers, services, etc):

First way.

enter image description here

First way is to create modules 'as is'. It is a bit more complicated because of some helpers services to store data to let modules communicate with each other.

I have controllers for A, B, C and MAIN with BUTTONS. If I will create 4 separate modules it will be problem to communicate with each other. I can solve this problem by creating Helper service to store data of B module.

The process will be:

  1. Get data through B controller
  2. Store it in Helper service
  3. A and C will listen Helper service and if data is changed in it, they change their state
  4. Data of A and C module are storted in HelperA and HelperC services.
  5. When I need to save result of work, I collect data from Helper, HelperA and HelperC services.

Pros of this way:

  • this method provide more modularity

Cons of this way:

  • 3 more services – helper, HelperC, HelperA
  • non-obvious parameter transfer because of helper

Second way. Simplier.

enter image description here

I will create MAIN + B + BUTTONS controller, A and C controllers. No Helper service. Data from B controller will be passed to C and A controllers 'as is'. No non-obvious services.

Process:

  1. Get data through B controller
  2. Pass data from B to A and C throught in params of A and C, also A and C have out parameters to provide B with data was changed in A and C.
  3. When I need to save data, I have all data in B controller and it is easier to collect them.

Pros:

  • obvious passing of parameters
  • less code

Cons:

  • less modularity

The question is: what is correct way?

Our team need modularity to split different groups of functions to different module and to speed up speed of development. Obvious, that when 3-4 developers works on 1 programm entity, splitted by modules, it is more faster way of creating final product.

It is not problem to perform 1 or 2 way. It is very easy to create 3 more services and use them correctly in controllers. The problem: "Is this separation is actually needed?"

Also, I don't want modularity because of modularity. I have doubts because A and C depend on B, thats why I think I shouldn't make B as separated module, but modularity... urgh... help me please? :)

Aucun commentaire:

Enregistrer un commentaire