Skip to content

Commit 01f51e1

Browse files
committed
Add lack of contents
1 parent eb08af6 commit 01f51e1

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

i18n/README-ja-jp.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
* [ページ・コントローラ](#ページコントローラ)
3535
* [その他](#その他)
3636
* [モジュール・パターン](#モジュールパターン)
37-
* [データ・マッパ](#データマッパ)
37+
* [データ・マッパ](#データマッパ)
38+
* [Observer Pattern as an External Service](#observer-pattern-as-an-external-service)
3839
* [References](#references)
3940

4041
<!--endtoc-->
@@ -45,6 +46,11 @@
4546
このドキュメントは読者にデザインやアーキテクチャのパターンに親しんでもらおうとして書かれているものではありませんので、オブジェクト指向やデザイン・パターン、アーキテクチャ・パターンについての基本的な理解をしておくことをおすすめします。
4647
このドキュメントの目的は、AngularJSやAngularJSのシングル・ページ・アプリケーションにどれだけ様々なソフトウェア・デザインやアーキテクチャのパターンが採用されているかを述べることです。
4748

49+
## Translations
50+
51+
- [Japanese Translation](https://github.com/mgechev/angularjs-in-patterns/blob/master/i18n/README-ja-jp.md) by [morizotter](https://twitter.com/morizotter)
52+
- [Russian Translation](http://habrahabr.ru/post/250149/)
53+
4854
## はじめに
4955

5056
このドキュメントはAngularJSの概要を簡単に見ていくところから始まります。「AngularJSの概要」ではAngularJSの主なコンポーネントとして、ディレクティブ、フィルタ、コントローラ、サービス、スコープを見ていきます。2番目のセクションでは、フレームワークの内部で利用されているそれぞれのデザインとアーキテクチャのパターンを解説していきます。いくつかのコンポーネントで利用されているパターンがあった場合は、言及していきます。
@@ -822,6 +828,8 @@ function ExampleCtrl($scope) {
822828

823829
JavaScriptコミュニティではこのパターンはパブリッシュ/サブスクライブとして知られています。
824830

831+
For a best practice example see [Observer Pattern as an External Service](#observer-pattern-as-an-external-service)
832+
825833
#### チェーン・オブ・レスポンシビリティ
826834

827835
>チェーン・オブ・レスポンシビリティ・パターンはコマンド・オブジェクトと続く一連の処理オブジェクトからなるデザイン・パターンです。それぞれの処理オブジェクトは処理が可能なコマンド・オブジェクトを規定するロジックを持っています。残りの部分は次の処理オブジェクトに連鎖的に渡されます。新しい処理オブジェクトを連鎖の末尾に追加するメカニズムも存在しています。
@@ -1086,6 +1094,66 @@ function MainCtrl($scope, User) {
10861094
</div>
10871095
```
10881096
1097+
### Observer Pattern as an External Service
1098+
1099+
##### About
1100+
1101+
Below is an example taken from [here](https://github.com/greglbd/angular-observer-pattern). This is an angular factory which creates a service implementing 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.
1102+
1103+
**Use Case:** You would use this pattern to communicate between 2 controllers that use the same model but are not connected in anyway.
1104+
1105+
##### Controller Example
1106+
1107+
Below example shows how to attach, notify and detach an event.
1108+
1109+
```javascript
1110+
angular.module('app.controllers')
1111+
.controller('ObserverExample', ObserverExample);
1112+
ObserverExample.$inject= ['ObserverService', '$timeout'];
1113+
1114+
function ObserverExample(ObserverService, $timeout) {
1115+
var vm = this;
1116+
var id = 'vm1';
1117+
1118+
ObserverService.attach(callbackFunction, 'let_me_know', id)
1119+
1120+
function callbackFunction(params){
1121+
console.log('now i know');
1122+
ObserverService.detachByEvent('let_me_know')
1123+
}
1124+
1125+
$timeout(function(){
1126+
ObserverService.notify('let_me_know');
1127+
}, 5000);
1128+
}
1129+
```
1130+
Alternative way to remove event
1131+
1132+
```javascript
1133+
angular.module('app.controllers')
1134+
.controller('ObserverExample', ObserverExample);
1135+
ObserverExample.$inject= ['ObserverService', '$timeout', '$scope'];
1136+
1137+
function ObserverExample(ObserverService, $timeout, $scope) {
1138+
var vm = this;
1139+
var id = 'vm1';
1140+
ObserverService.attach(callbackFunction, 'let_me_know', id)
1141+
1142+
function callbackFunction(params){
1143+
console.log('now i know');
1144+
}
1145+
1146+
$timeout(function(){
1147+
ObserverService.notify('let_me_know');
1148+
}, 5000);
1149+
1150+
// Cleanup listeners when this controller is destroyed
1151+
$scope.$on('$destroy', function handler() {
1152+
ObserverService.detachByEvent('let_me_know')
1153+
});
1154+
}
1155+
```
1156+
10891157
## References
10901158
10911159
1. [Wikipedia](https://en.wikipedia.org/wiki). The source of all brief descriptions of the design patterns is wikipedia.

0 commit comments

Comments
 (0)