Skip to content

Commit 9e7fd89

Browse files
committed
Add support for extensions to service interface
Custom interface additions can now be added by an application implementor for the specific needs of their application.
1 parent 7970428 commit 9e7fd89

File tree

4 files changed

+292
-262
lines changed

4 files changed

+292
-262
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ app.config(['$navigationProvider', function ($navigationProvider) {
5050
activeLinkDecorator: undefined,
5151
inactiveLinkDecorator: undefined,
5252
securityService: undefined,
53+
extensions: undefined,
5354
roleToAudienceMapFunction: function (userRole) {
5455
return userRole;
5556
},
@@ -62,6 +63,10 @@ app.config(['$navigationProvider', function ($navigationProvider) {
6263
}]);
6364
```
6465

66+
### extensions
67+
68+
All properties (own and inherited) of the extensions object will be available as native to the $navigation service API. The extensions object is applied using the [_.defaults(...)](https://lodash.com/docs/#defaults) method and cannot overwrite any of the existing API properties. This is intended to provide implementors with a way to add objects or functions that are application specific and should fall within the context of the navigation service to expose, e.g., a hash of link objects or a function to re-write links.
69+
6570
## API
6671

6772
### inAudience

ng-navigation-service.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
var configuration = {
1919
activeLinkDecorator: undefined,
2020
inactiveLinkDecorator: undefined,
21+
links: undefined,
2122
securityService: undefined,
23+
extensions: undefined,
2224
roleToAudienceMapFunction: function (userRole) {
2325
return userRole;
2426
},
@@ -59,7 +61,9 @@
5961
return secService;
6062
};
6163

62-
return {
64+
var api = {
65+
links: configuration.links,
66+
6367
/**
6468
* returns true if the user is in any of the specified audiences.
6569
*/
@@ -160,6 +164,7 @@
160164
return _.words(location.toLowerCase(), /[\w\-]+/g);
161165
}
162166
};
167+
return _.defaults(api, configuration.extensions);
163168
}];
164169
});
165170
return angular;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-navigation-service",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"author": "Justin Saunders (https://github.com/justinsa)",
55
"contributors": [
66
"Justin Saunders (https://github.com/justinsa)"

0 commit comments

Comments
 (0)