Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added more explanations to huuuuuge article

  • Loading branch information...
commit d4ae2275ed22e881e865635b23fb0817386c2333 1 parent 0fb3f31
@btford authored
Showing with 11 additions and 5 deletions.
  1. +11 −5 jade/blog/huuuuuge-angular-apps.jade
View
16 jade/blog/huuuuuge-angular-apps.jade
@@ -43,7 +43,9 @@ block main
As you add more files, it might make sense to create subdirectories to further organize controllers and services. For instance, I often find myself making a `models` directory inside of `services`. My rule of thumb is to only further sort files into directories if there is some rational hierarchy by which you can organize the files.
### Files
- Each file should have one "thing" in it, where a "thing" is a controller, directive, filter, or service. I would make an exception for closely related directives. For example, if you have an `<pane>` directive that requires `<panel>` to be a parent, those should be in the same file.
+ Each file should have one "thing" in it, where a "thing" is a controller, directive, filter, or service. This makes for small, focused files. It also helps create a litmus test for how APIs are doing. If you find yourself flipping back and forth through files too frequently, this is an indication that your APIs are too complex. You should rethink, refactor, and simplify.
+
+ I would make an exception for closely related directives. For example, if you have an `<pane>` directive that requires `<panel>` to be a parent, those should be in the same file.
### Modules
Define and configure all modules in `app.js`:
@@ -67,7 +69,9 @@ block main
APIs should be layered. Controllers especially should not be synthesizing different levels of abstraction.
### Directives
- Use an app-specific prefix for directives. For example, if your app is called "The Best Todo List App Ever," you might prefix your directives with "btla."
+ Use an app-specific prefix for directives. This is useful for avoiding collisions with 3rd party components. On the subject of 3rd party components, there's a growing community site called [ngmodules](http://ngmodules.org/) that looks promising.
+
+ For example, if your app is called "The Best Todo List App Ever," you might prefix your directives with "btla."
:javascript
angular.module('yourAppDep').directive('btlaControlPanel', function () {
@@ -83,12 +87,14 @@ block main
});
:markdown
### Models
- AngularJS is unique among JavaScript frameworks in that it gives you complete control over your model layer. I think this is one of the great strengths of Angular, because at the core of your application is your data, and data varies wildly from app to app.
+ AngularJS is unique among JavaScript frameworks in that it gives you complete control over your model layer. I think this is one of the great strengths of Angular, because at the core of your application is your data, and data varies wildly from app to app. My biggest recommendation is to consider what data you will be using, and how you will store it.
+
+ If you're using a NoSQL datastore like CouchDB or MongoDB, you might be content working with plain-old JavaScript Objects (POJO) and functional helpers. If you're using a relational database like MySQL, you might want psuedo-classes with methods for mutating, serializing, and deserializing the data. If your server provides a RESTful interface, [`$resource`](http://docs.angularjs.org/api/ngResource.$resource) might be a good place to start. These are just suggestions; any of these approaches might be useful outside of the situations I described. With so many options, this is sometimes a challenging decision to make. But thinking hard about your data will pay off.
- If you're using something like CouchDB or MongoDB, you might be content working with plain-old JavaScript Objects (POJO). If you're coming from a Backbone.js background, you'll find many of the great utilities for dealing with models in [Underscore.js](http://documentcloud.github.com/underscore/), the utility library that powers Backbone.
+ In general, you'll find many great utilities for dealing with models in [Underscore.js](http://documentcloud.github.com/underscore/), the utility library that also powers Backbone.js.
### Controllers
- Controller names should start with a capital letter and end with "Ctrl" by convention.
+ By convention, controller names should start with a capital letter and end with "Ctrl".
:javascript
angular.module('yourAppDep').controller('MyCtrl', function () {
Please sign in to comment.
Something went wrong with that request. Please try again.