Skip to content

Commit 38d2652

Browse files
committed
Merge pull request johnpapa#476 from johnpapa/fix/naming
Fix/naming
2 parents e4d072b + ee8d660 commit 38d2652

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

README.md

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,11 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
475475
476476
```javascript
477477
/* recommended */
478-
function Sessions(dataservice) {
478+
function Sessions(sessionDataService) {
479479
var vm = this;
480480

481481
vm.gotoSession = gotoSession;
482-
vm.refresh = dataservice.refresh; // 1 liner is OK
482+
vm.refresh = sessionDataService.refresh; // 1 liner is OK
483483
vm.search = search;
484484
vm.sessions = [];
485485
vm.title = 'Sessions';
@@ -505,7 +505,7 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
505505
* avoid
506506
* Using function expressions.
507507
*/
508-
function Avengers(dataservice, logger) {
508+
function Avengers(avengersService, logger) {
509509
var vm = this;
510510
vm.avengers = [];
511511
vm.title = 'Avengers';
@@ -517,7 +517,7 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
517517
}
518518

519519
var getAvengers = function() {
520-
return dataservice.getAvengers().then(function(data) {
520+
return avengersService.getAvengers().then(function(data) {
521521
vm.avengers = data;
522522
return vm.avengers;
523523
});
@@ -537,7 +537,7 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
537537
* Using function declarations
538538
* and bindable members up top.
539539
*/
540-
function Avengers(dataservice, logger) {
540+
function Avengers(avengersService, logger) {
541541
var vm = this;
542542
vm.avengers = [];
543543
vm.getAvengers = getAvengers;
@@ -552,7 +552,7 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
552552
}
553553

554554
function getAvengers() {
555-
return dataservice.getAvengers().then(function(data) {
555+
return avengersService.getAvengers().then(function(data) {
556556
vm.avengers = data;
557557
return vm.avengers;
558558
});
@@ -615,7 +615,7 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
615615
function checkCredit() {
616616
return creditService.isOrderTotalOk(vm.total)
617617
.then(function(isOk) { vm.isCreditOk = isOk; })
618-
.catch(showServiceError);
618+
.catch(showError);
619619
};
620620
}
621621
```
@@ -1626,14 +1626,14 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
16261626
.controller('Avengers', Avengers);
16271627

16281628
/* @ngInject */
1629-
function Avengers(storageService, avengerService) {
1629+
function Avengers(storage, avengerService) {
16301630
var vm = this;
16311631
vm.heroSearch = '';
16321632
vm.storeHero = storeHero;
16331633

16341634
function storeHero() {
16351635
var hero = avengerService.find(vm.heroSearch);
1636-
storageService.save(hero.name, hero);
1636+
storage.save(hero.name, hero);
16371637
}
16381638
}
16391639
```
@@ -1646,18 +1646,18 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
16461646
.controller('Avengers', Avengers);
16471647

16481648
/* @ngInject */
1649-
function Avengers(storageService, avengerService) {
1649+
function Avengers(storage, avengerService) {
16501650
var vm = this;
16511651
vm.heroSearch = '';
16521652
vm.storeHero = storeHero;
16531653

16541654
function storeHero() {
16551655
var hero = avengerService.find(vm.heroSearch);
1656-
storageService.save(hero.name, hero);
1656+
storage.save(hero.name, hero);
16571657
}
16581658
}
16591659

1660-
Avengers.$inject = ['storageService', 'avengerService'];
1660+
Avengers.$inject = ['storage', 'avengerService'];
16611661
```
16621662
16631663
Note: If `ng-annotate` detects injection has already been made (e.g. `@ngInject` was detected), it will not duplicate the `$inject` code.
@@ -1979,15 +1979,19 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
19791979
function AvengersController() { }
19801980
```
19811981
1982-
### Factory Names
1982+
### Factory and Service Names
19831983
###### [Style [Y125](#style-y125)]
19841984
1985-
- Use consistent names for all factories named after their feature. Use camel-casing for services and factories. Avoid prefixing factories and services with `$`.
1985+
- Use consistent names for all factories and services named after their feature. Use camel-casing for services and factories. Avoid prefixing factories and services with `$`. Only suffix service and factories with `Service` when it is not clear what they are (i.e. when they are nouns).
19861986
19871987
*Why?*: Provides a consistent way to quickly identify and reference factories.
19881988
19891989
*Why?*: Avoids name collisions with built-in factories and services that use the `$` prefix.
19901990
1991+
*Why?*: Clear service names such as `logger` do not require a suffix.
1992+
1993+
*Why?*: Service names such as `avengers` are nouns and require a suffix and should be named `avengersService`.
1994+
19911995
```javascript
19921996
/**
19931997
* recommended
@@ -2001,6 +2005,26 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
20012005
function logger() { }
20022006
```
20032007
2008+
```javascript
2009+
/**
2010+
* recommended
2011+
*/
2012+
2013+
// credit.service.js
2014+
angular
2015+
.module
2016+
.factory('creditService', creditService);
2017+
2018+
function creditService() { }
2019+
2020+
// credit.service.js
2021+
angular
2022+
.module
2023+
.service('customersService', customersService);
2024+
2025+
function customersService() { }
2026+
```
2027+
20042028
### Directive Component Names
20052029
###### [Style [Y126](#style-y126)]
20062030

0 commit comments

Comments
 (0)