| | 1 | = EdenMobile Coding Conventions = |
| | 2 | |
| | 3 | We want to follow a consistent coding style and naming conventions in EdenMobile. |
| | 4 | |
| | 5 | Everything that is not described on this page, should aim to follow the AngularJS Style Guide: |
| | 6 | |
| | 7 | - https://github.com/mgechev/angularjs-style-guide |
| | 8 | |
| | 9 | == Quotes == |
| | 10 | |
| | 11 | In alignment with Eden conventions, EdenMobile uses ''single quotes'' for string literals. |
| | 12 | {{{#!js |
| | 13 | var aString = 'use single quotes for string literals'; |
| | 14 | }}} |
| | 15 | |
| | 16 | == Naming Conventions == |
| | 17 | |
| | 18 | For names of AngularJS components of EdenMobile, such as services, directives, controllers, etc we use the '''em''' prefix. |
| | 19 | |
| | 20 | Controllers use the uppercase prefix: |
| | 21 | {{{#!js |
| | 22 | EdenMobile.controller('EMSynchronisationController', [ |
| | 23 | '$scope', '$state', '$stateParams', |
| | 24 | function($scope, $state, $stateParams) { |
| | 25 | |
| | 26 | } |
| | 27 | ]); |
| | 28 | }}} |
| | 29 | |
| | 30 | All other components use the lowercase prefix: |
| | 31 | {{{#!js |
| | 32 | EdenMobile.directive('emExampleDirective', [ |
| | 33 | '$compile', |
| | 34 | function($compile) { |
| | 35 | |
| | 36 | } |
| | 37 | ]); |
| | 38 | }}} |
| | 39 | |
| | 40 | For all other !JavaScript, we use '''camelCase''' (or !PascalCase, respectively) - not underscores as word separator - without the em-Prefix. |
| | 41 | |
| | 42 | Classes (=constructor functions) use the uppercase !PascalCase: |
| | 43 | {{{#!js |
| | 44 | function MyConstructor() { |
| | 45 | this.someAttribute = 'example'; |
| | 46 | } |
| | 47 | }}} |
| | 48 | |
| | 49 | Variables, attributes, methods use the lowercase camelCase: |
| | 50 | {{{#!js |
| | 51 | var doSomething = function(param) { |
| | 52 | var localVariable = param + 7; |
| | 53 | } |
| | 54 | }}} |
| | 55 | |
| | 56 | == Global Variables == |
| | 57 | |
| | 58 | Ideally, there should be only very few global variables - wherever possible, they should be defined as AngularJS services instead: |
| | 59 | |
| | 60 | {{{#!js |
| | 61 | EdenMobile.value('emGlobalVariable', 'some value'); |
| | 62 | }}} |
| | 63 | |
| | 64 | ...or using the factory method, respectively. |
| | 65 | |
| | 66 | Exceptions: |
| | 67 | |
| | 68 | - the {{{EdenMobile}}} module (=the application itself) |
| | 69 | - {{{CordovaApp}}}, which provides access to the Cordova layer |