AngularJS: Understanding design pattern

前端 未结 5 1618
逝去的感伤
逝去的感伤 2020-11-28 17:17

In the context of this post by Igor Minar, lead of AngularJS:

MVC vs MVVM vs MVP. What a controversial topic that many developers

5条回答
  •  忘掉有多难
    2020-11-28 17:42

    A minor issue comparing to the great advices in Artem's answer, but in terms of code readability, I found best to define the API completely inside the return object, to minimize going back and forth in code to look wheverer variables are defined:

    angular.module('myModule', [])
    // or .constant instead of .value
    .value('myConfig', {
      var1: value1,
      var2: value2
      ...
    })
    .factory('myFactory', function(myConfig) {
      ...preliminary work with myConfig...
      return {
        // comments
        myAPIproperty1: ...,
        ...
        myAPImethod1: function(arg1, ...) {
        ...
        }
      }
    });
    

    If the return object becomes looking "too crowded", that is a sign that the Service is doing too much.

提交回复
热议问题