Skip to content

Commit 32998e8

Browse files
committed
updated for readability
1 parent 937a020 commit 32998e8

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@ will produce the same result as the one above. The main difference here is that
794794
795795
![Observer](https://rawgit.com/mgechev/angularjs-in-patterns/master/images/observer.svg "Fig. 7")
796796

797-
## About
798-
This is an angular factory which reflects the Observer Pattern it works well with the ControllerAs method of working as it can be much more efficient that $scope.$watch and more specific to a unique scope or object than $emit and $broadcast when used correctly.
797+
##### About
798+
Below is an example taken from https://github.com/greglbd/angular-observer-pattern. This is an angular factory which reflects the Observer Pattern it works well with the ControllerAs method of working as it can be much more efficient that $scope.$watch and more specific to a unique scope or object than $emit and $broadcast when used correctly.
799799

800800
**Use Case:** You would use this pattern to communicate between 2 controllers that use the same model but are not connected in anyway
801801

@@ -805,25 +805,35 @@ This is an angular factory which reflects the Observer Pattern it works well wit
805805

806806
##### Methods
807807

808-
**_observerService.attach = function(callback, event, id)**
809-
810808
function adds a listener to an event with a callback which is stored against the event with it's corresponding id.
809+
```
810+
_observerService.attach = function(callback, event, id)
811+
```
811812

812-
**_observerService.detachById = function(id)**
813813

814814
function removes all occurences of one id from all events in the observer object
815+
```
816+
_observerService.detachById = function(id)
817+
```
815818

816-
**_observerService.detachByEvent = function(event)** __most commonly used and least expensive__
817819

818820
function removes all occurences of the event from the observer Object
821+
```
822+
_observerService.detachByEvent = function(event)
823+
```
819824

820-
**_observerService.detachByEventAndId = function(event, id)**
821825

822826
removes all callbacks for an id in a specific event from the observer object
827+
```
828+
_observerService.detachByEventAndId = function(event, id)
829+
```
830+
823831

824-
**_observerService.notify = function(event, parameters)**
832+
Notifies all observers of a specific event, can pass a params variable of any type
833+
```
834+
_observerService.notify = function(event, parameters)
835+
```
825836

826-
notifies all observers of a specific event, can pass a params variable of any type
827837

828838
##### Controller Example
829839
Below example shows how to attach, notify and detach an event.

0 commit comments

Comments
 (0)