Skip to content

Commit 5f20398

Browse files
committed
Update decorator
1 parent 88b4356 commit 5f20398

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ According to the Gang of Four, MVC is nothing more than combination of:
379379
- Composite
380380
- Observer
381381

382-
They state that the view is composition of components. In AngularJS the situation is similar. Our views are formed by a composition of directives and DOM elements.
382+
They state that the view is composition of components. In AngularJS the situation is similar. Our views are formed by a composition of directives and DOM elements, on which these directives could be applied.
383383

384384
Lets look at the following example:
385385

@@ -422,7 +422,7 @@ In the second, JavaScript, example we see that the `template` property of the di
422422
423423
![Decorator](./images/decorator.png "Fig. 4")
424424

425-
AngularJS provides out-of-the-box way for extending/changing the functionality of already existing services. Using the method `decorator` of `$provide` you can create "wrapper" of any service you have previously defined:
425+
AngularJS provides out-of-the-box way for extending, enchanting the functionality of already existing services. Using the method `decorator` of `$provide` you can create "wrapper" of any service you have previously defined:
426426

427427
```JavaScript
428428
myModule.controller('MainCtrl', function (foo) {
@@ -453,6 +453,8 @@ myModule.config(function ($provide) {
453453
```
454454
The example above defines new service called `foo`. In the `config` callback is called the method `$provide.decorator` with first argument `"foo"`, which is the name of the service, we want to decorate and second argument factory function, which implements the actual decoration. `$delegate` keeps reference to the original service `foo`. Using the dependency injection mechanism of AngularJS, reference to this local dependency is passed as first argument. We decorate the service by overriding its method `bar`. We extend `bar` by invoking one more `console.log statement` - `console.log('Decorated');` and after that call the original `bar` method into appropriate context.
455455

456+
Using this pattern is especially useful when we need to modify the functionality of third party services.
457+
456458
### Facade
457459

458460
>A facade is an object that provides a simplified interface to a larger body of code, such as a class library. A facade can:

0 commit comments

Comments
 (0)