Advertisement
Guest User

Untitled

a guest
May 6th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. # Global Guidlines
  2.  
  3. ## Filesystem Naming:
  4.  
  5. * Lowercase
  6. * Dashes Between Words
  7. * Apply to Folder & Files
  8.  
  9. ```
  10. my-folder / my-file.css
  11. ```
  12.  
  13. ## Function Naming:
  14.  
  15. ```
  16. #!javascript
  17. function myFunction() {
  18. //some code
  19. }
  20. ```
  21.  
  22. ## Constructor Naming:
  23.  
  24. ```
  25. #!javascript
  26. function MenWithTwoLegs() {
  27. //some code
  28. }
  29. ```
  30.  
  31. ## Variables:
  32.  
  33. * Init all variables on top of the file/function.
  34. * Variables naming write in Lowercase and with Underscore:
  35.  
  36. ```
  37. #!javascript
  38. var my_lucky_number = 16,
  39. my_unlucky_number;
  40. // some code...
  41. ```
  42.  
  43. # AngularJS Guidlines
  44.  
  45. ** 1 Component per file.
  46. For search, minimalize files, for relocate and edit code. **
  47.  
  48. ## Naming Filesystem
  49.  
  50. ```
  51. app.mdl.js
  52.  
  53. product-list.ctrl.js
  54. product-list.tpl.html
  55. product-list.css
  56.  
  57. product-box.drv.js
  58. product-box.drv.test.js
  59.  
  60. .fltr .srv .cnst .val .mock and etc...
  61. ```
  62.  
  63. ## Namespacing Components
  64.  
  65. ** src/scripts/core/main.ctrl.js **
  66.  
  67. ```
  68. #!javascript
  69. angular.module('myApp')
  70. .controller
  71. ('myApp.core.mainCtrl',
  72. ['$scope', function($scope){
  73. }]);
  74. ```
  75.  
  76. ## States/Routing
  77.  
  78. * Use only UI-Router
  79. * Use Dynamic Routing. ``` \state:id ```
  80. * Think in states:
  81.  
  82. ```
  83. #!javascript
  84. $stateProvider.state('product',
  85. {
  86. controller: 'productCtrl'
  87. templateUrl: '...'
  88. url: '/:productId'
  89. }
  90. );
  91. ```
  92.  
  93. ## Folder Structure
  94.  
  95. * Core → The App’ Sections
  96. * Common → Repeated Through Core
  97. * Nested States = Nested Folders
  98.  
  99. ```
  100. scripts/
  101. common/ --> universal stuff, base layers
  102. services/
  103. directives/
  104. core/ --> states
  105. app.mdl.js
  106. products/
  107. products.ctrl.js
  108. product-details/
  109. ```
  110.  
  111. ## Keep everything together:
  112.  
  113. ```
  114. users-list/
  115. users-list.ctrl.js
  116. users-list.ctrl.test.js
  117. users-list.tpl.html
  118. users-list.scss
  119.  
  120. smart-tree/
  121. smart-tree.drv.js
  122. smart-tree.drv.test.js
  123. smart-tree.tpl.html
  124. smart-tree.scss
  125. ```
  126.  
  127. ## Separate to modules. For:
  128. * Faster Unit Testing
  129. * Gives Context
  130. * Easier To Remove Parts Of The App
  131.  
  132. ** scripts/core/user/user.mdl.js **
  133.  
  134. ```
  135. #!javascript
  136. .module('myApp.core.user', [])
  137. .controller(
  138. 'myApp.core.user.userCtrl', ...);
  139.  
  140. angular
  141. .module('myApp.common.services')
  142. .service(
  143. 'myApp.common.services.product', ...);
  144. ```
  145.  
  146. ##Services
  147.  
  148. One Service --> return One Dependence
  149.  
  150. ```
  151. #!javascript
  152. angular.module('...')
  153. .factory('userService',
  154. function(){
  155. return {
  156. gettingUsers: {} // some code
  157. }
  158. });
  159. ```
  160.  
  161. ## Directives
  162.  
  163. * Isolated Scope
  164. * Inject Only Private Services
  165.  
  166. ** userBox Directive: **
  167. ```
  168. #!javascript
  169. scope: {
  170. userModel: '=',
  171. userClicked: '&',
  172. // params: user
  173. }
  174. ```
  175. ```
  176. #!html
  177. <user-box user-model=”data”
  178. user-clicked=”onClick(user)”></user-box>
  179. ```
  180.  
  181.  
  182. # Recomendations:
  183.  
  184. ### 1. Autogenerate File linking by ** Gulp.js / Grunt.js **
  185.  
  186. ** index.html **
  187. ```
  188. #!html
  189. <!-- include:
  190. “type”:”js”,
  191. “files”:
  192. [“scripts/**/*.mdl.js',
  193. “scripts/**/*.js”,
  194. “!scripts/**/*.test.js”]
  195. -->
  196. ```
  197.  
  198. ### 2. Unit test your code (Karma an enxample)
  199.  
  200. ```
  201. #!javascript
  202. describe('userCtrl', function(){
  203. it('Should…', function(){
  204. expect(userClicked)
  205. .toBe(true)
  206. }
  207. })
  208.  
  209. Given(function(){ list empty });
  210. When(function(){ user clicks });
  211. Then(function(){ expect() });
  212. ```
  213.  
  214. ### 3. Manage your packages with bower.io
  215. ### 4. Use promises (Angular.js)
  216. ### 5. Use CSS preprocessors: SCSS, STYLUS, LESS
  217. ### 6. Build with Gulp.js
  218.  
  219.  
  220. # Project Developed by:
  221.  
  222. ### Nikita Lavrenko
  223.  
  224. * Skype: nikita.lavrenko
  225. * Email: lavrenonik@gmail.com
  226. * LinkedIn: www.linkedin.com/in/niklavr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement